﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using DBService;
using YArchitech.Controls.HeaderGridView;
using YArchitech.Revit;
using YJKFamilyLibDataManager;
using LampUseFactorManager;

namespace YJKFamilyLibManager.FamilyLibModule
{
	public partial class DlgMain : System.Windows.Forms.Form, IDlgBase
	{
		public static DlgMain GetInstance(UIApplication app)
		{
			if (DlgMain.main == null || DlgMain.main.IsDisposed)
			{
				DlgMain.main = new DlgMain(app);
			}
			return DlgMain.main;
		}

		public void WhenSubjectChange()
		{
			if (this.currentSubject != null)
			{
				this.tsmiAddFamily.Enabled = false;
				this.btnAddCategory.Enabled = true;
				this.btnDelCategory.Enabled = false;
				this.btnAddFamily.Enabled = false;
				this.btnDelFamily.Enabled = false;
				this.btnEditCategory.Enabled = false;
				this.btnEditFamily.Enabled = false;
				this.btnAddType.Enabled = false;
				this.btnEditType.Enabled = false;
				this.btnDelType.Enabled = false;
				this.outputToolStripMenuItem.Enabled = true;
				this.dgvType.DataSource = "";
				this.dgvType.ContextMenuStrip = null;
				this.toolStripStatusLabel1.Text = this.CurrentSubject.Name + "-";
				if (this.CurrentSubject.Name == "我的收藏")
				{
					this.lvFamily.ContextMenuStrip = this.cmsMyCollectFamily;
					return;
				}
				this.lvFamily.ContextMenuStrip = this.cmsFamily;
			}
		}

		public void WhenCategoryChange()
		{
			if (this.currentCategory != null)
			{
				this.tsmiAddFamily.Enabled = true;
				this.btnAddCategory.Enabled = true;
				this.btnDelCategory.Enabled = true;
				this.btnAddFamily.Enabled = true;
				this.btnDelFamily.Enabled = false;
				this.btnEditCategory.Enabled = true;
				this.outputToolStripMenuItem.Enabled = false;
				this.btnEditFamily.Enabled = false;
				this.btnAddType.Enabled = false;
				this.btnEditType.Enabled = false;
				this.btnDelType.Enabled = false;
				this.btnDownload.Enabled = false;
				this.dgvType.DataSource = "";
				this.dgvType.ContextMenuStrip = null;
				this.toolStripStatusLabel1.Text = this.CurrentSubject.Name + "-" + this.CurrentCategory.Name;
				if (this.CurrentSubject.Name == "我的收藏")
				{
					this.lvFamily.ContextMenuStrip = this.cmsMyCollectFamily;
				}
				else
				{
					this.lvFamily.ContextMenuStrip = this.cmsFamily;
				}
				this.mListFamilys = this.CurrentCategory.GetAllFamilies(false, this.checkType);
				this.pageCount = this.ComputePageCount();
				this.label2.Text = "/" + this.pageCount.ToString();
				this.cbxPageCount.Items.Clear();
				for (int i = 1; i <= this.pageCount; i++)
				{
					this.cbxPageCount.Items.Add(i);
				}
				if (this.cbxPageCount.Items.Count > 0)
				{
					this.cbxPageCount.SelectedIndex = 0;
					return;
				}
			}
			else
			{
				this.btnAddFamily.Enabled = false;
				this.btnTop.Enabled = false;
				this.btnPrevious.Enabled = false;
				this.btnNext.Enabled = false;
				this.btnBottom.Enabled = false;
			}
		}

		public void WhenFamilyChange()
		{
			if (this.CurrentFamily == null)
			{
				this.btnAddType.Enabled = false;
				this.btnDelFamily.Enabled = false;
				this.btnEditFamily.Enabled = false;
				this.btnAddType.Enabled = false;
				this.btnDownload.Enabled = false;
				return;
			}
			DbCategory dbCategory = this.currentFamily.Database.CategoryTable[this.currentFamily.ParentId];
			DbSubject dbSubject = this.currentFamily.Database.SubjectTable.AllSubject()[0];
			this.btnAddType.Enabled = true;
			this.btnDelFamily.Enabled = true;
			this.btnEditFamily.Enabled = true;
			this.btnAddType.Enabled = true;
			this.btnDownload.Enabled = true;
			this.dgvType.ContextMenuStrip = this.cmsType;
			this.ShowType();
			if (this.CurrentCategory == null)
			{
				this.toolStripStatusLabel1.Text = dbSubject + "-" + this.CurrentFamily;
				return;
			}
			this.toolStripStatusLabel1.Text = string.Concat(new object[]
			{
				dbSubject.Name,
				"-",
				dbCategory.Name,
				"\\",
				this.CurrentFamily
			});
		}

		public UIApplication UiApp
		{
			get
			{
				return this.m_uiApp;
			}
			set
			{
				this.m_uiApp = value;
			}
		}

		public DbSubject CurrentSubject
		{
			get
			{
				if (this.CurrentFamily != null)
				{
					DbSubject dbSubject = this.CurrentFamily.Database.SubjectTable.AllSubject()[0];
					if (this.currentSubject == null || dbSubject.Guid != this.currentSubject.Guid)
					{
						this.currentSubject = dbSubject;
						return dbSubject;
					}
				}
				return this.currentSubject;
			}
			set
			{
				this.currentSubject = value;
				this.WhenSubjectChange();
			}
		}

		public DbCategory CurrentCategory
		{
			get
			{
				if (this.CurrentFamily != null)
				{
					DbCategory dbCategory = this.CurrentFamily.Database.CategoryTable[this.CurrentFamily.ParentId];
					if (this.currentCategory == null || dbCategory.Guid != this.currentCategory.Guid)
					{
						this.currentCategory = dbCategory;
						return dbCategory;
					}
				}
				return this.currentCategory;
			}
			set
			{
				this.currentCategory = value;
				this.WhenCategoryChange();
			}
		}

		public DbFamily CurrentFamily
		{
			get
			{
				return this.currentFamily;
			}
			set
			{
				this.currentFamily = value;
				this.WhenFamilyChange();
			}
		}

		public DlgMain(UIApplication app)
		{
			this.m_uiApp = app;
			this.InitializeComponent();
			this.sorter = new ListViewSorter();
			this.lvFamily.ListViewItemSorter = this.sorter;
			this.sorter.SortOrder = SortOrder.Ascending;
		}

		private void FrmMain_Load(object sender, EventArgs e)
		{
			this.trCategory.AfterLabelEdit += this.trCategory_AfterLabelEdit;
			this.trCategory.ItemDrag += this.trFamilyTree_ItemDrag;
			this.lvFamily.ItemDrag += this.listView1_ItemDrag;
			this.lvFamily.DragEnter += this.listView1_DragEnter;
			this.lvFamily.AfterLabelEdit += this.listView1_AfterLabelEdit;
			this.trCategory.DragEnter += this.trFamilyTree_DragEnter;
			this.trCategory.DragOver += this.trFamilyTree_DragOver;
			this.trCategory.MouseClick += this.trFamilyTree_MouseClick;
			this.trCategory.DragDrop += this.trFamilyTree_DragDrop;
			this.trCategory.MouseDown += this.trFamilyTree_MouseDown;
			this.dgvType.SortCompare += this.dgvType_SortCompare;
			this.dgvType.ColumnHeaderMouseClick += this.dgvType_ColumnHeaderMouseClick;
			DbData dbData = ConfigUtils.ReadFamilyLibXmlFile("族库类型", this.m_uiApp.Application.VersionNumber);
			if (dbData is LocalDbData)
			{
				this.rbLocal.Checked = true;
			}
			else if (dbData is UserDbData)
			{
				this.rbUser.Checked = true;
			}
			else if (dbData is ServerDbData)
			{
				this.rbServer.Checked = true;
			}
			else if (dbData is CompanyDbData)
			{
				this.rbCompany.Checked = true;
			}
			this.autoLogin();
		}

		private void dgvType_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
		}

		private void dgvType_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
		{
			e.SortResult = string.Compare(e.CellValue1.ToString(), e.CellValue2.ToString());
			if (e.SortResult == 0)
			{
				e.SortResult = ((Convert.ToDouble(this.dgvType.Rows[e.RowIndex1].Cells[e.Column.Name]) > Convert.ToDouble(this.dgvType.Rows[e.RowIndex2].Cells[e.Column.Name])) ? e.RowIndex1 : e.RowIndex2);
			}
			e.Handled = true;
		}

		private void listView1_DragEnter(object sender, DragEventArgs e)
		{
			e.Effect = DragDropEffects.Move;
		}

		private void trFamilyTree_ItemDrag(object sender, ItemDragEventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count > 0)
			{
				base.DoDragDrop(e.Item, DragDropEffects.Move);
			}
		}

		private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
		{
			this.lvFamily.DoDragDrop(this.lvFamily.SelectedItems[0], DragDropEffects.Copy | DragDropEffects.Move);
		}

		private void trFamilyTree_DragEnter(object sender, DragEventArgs e)
		{
			if (e.Data.GetDataPresent(typeof(TreeNode)))
			{
				e.Effect = DragDropEffects.Move;
				return;
			}
			ListViewItem listViewItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
			if (listViewItem != null)
			{
				e.Effect = DragDropEffects.Move;
				return;
			}
			this.Cursor = Cursors.No;
		}

		private void trFamilyTree_DragOver(object sender, DragEventArgs e)
		{
			this.Cursor = Cursors.Hand;
		}

		private void trFamilyTree_DragDrop(object sender, DragEventArgs e)
		{
			this.Cursor = Cursors.Default;
            System.Drawing.Point pt = ((TreeView)sender).PointToClient(new System.Drawing.Point(e.X, e.Y));
			TreeNode nodeAt = ((TreeView)sender).GetNodeAt(pt);
			if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
			{
				TreeNode treeNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
				if (nodeAt == treeNode)
				{
					return;
				}
				TreeNode treeNode2 = this.FindRoot(treeNode);
				TreeNode treeNode3 = this.FindRoot(nodeAt);
				if (treeNode2.Text != treeNode3.Text)
				{
					MessageBox.Show("只能在同一专业下修改分类从属关系！", "族库管理");
					return;
				}
				if (!(treeNode.Tag is DbCategory) || !(nodeAt.Tag is Parent))
				{
					return;
				}
				try
				{
					Parent parent = (Parent)nodeAt.Tag;
					DbCategory dbCategory = (DbCategory)treeNode.Tag;
					if (!dbCategory.ParentId.Equals(parent.Guid) && MessageBox.Show(string.Concat(new string[]
					{
						"是否要将\"",
						dbCategory.Name,
						"\"分类移至\"",
						parent.Name,
						"\"？"
					}), "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK && dbCategory.ReParent(parent))
					{
						nodeAt.Nodes.Add(treeNode.Clone() as TreeNode);
						treeNode.Remove();
						nodeAt.ExpandAll();
					}
					return;
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					return;
				}
			}
			if (nodeAt.Tag is DbCategory)
			{
				List<DbFamily> list = new List<DbFamily>();
				foreach (object obj in this.lvFamily.SelectedItems)
				{
					ListViewItem listViewItem = (ListViewItem)obj;
					DbFamily item = (DbFamily)listViewItem.Tag;
					list.Add(item);
				}
				if (list.Count < 1)
				{
					return;
				}
				Parent parent2 = (Parent)nodeAt.Tag;
				if (!list[0].Database.Equals(parent2.Database))
				{
					TreeNode treeNode4 = this.FindRoot(nodeAt);
					if (treeNode4.Name == "我的收藏")
					{
						this.doAddFamilyToMyCollect(list, nodeAt);
						return;
					}
					MessageBox.Show("只能在同一专业下修改族从属关系！", "族库管理");
					return;
				}
				else
				{
					if (this.CurrentCategory == null)
					{
						DbSubject dbSubject = this.CurrentSubject;
					}
					else
					{
						DbCategory dbCategory2 = this.CurrentCategory;
					}
					try
					{
						if (!list[0].ParentId.Equals(parent2.Guid))
						{
							string text = list[0].Name;
							for (int i = 1; i < list.Count; i++)
							{
								text = text + "," + list[i].Name;
							}
							if (MessageBox.Show(string.Concat(new string[]
							{
								"是否要将族\"",
								text,
								"\"移至\"",
								parent2.Name,
								"\"分类？"
							}), "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
							{
								foreach (DbFamily dbFamily in list)
								{
									this.mListFamilys.Remove(dbFamily);
									dbFamily.ChangeParent(parent2);
								}
								int num = this.ComputePageCount();
								int num2 = this.cbxPageCount.SelectedIndex;
								if (num < this.pageCount)
								{
									this.pageCount = num;
									this.label2.Text = "/" + this.pageCount.ToString();
									this.cbxPageCount.Items.Clear();
									for (int j = 1; j <= this.pageCount; j++)
									{
										this.cbxPageCount.Items.Add(j);
									}
									if (num2 >= this.cbxPageCount.Items.Count)
									{
										num2 = this.cbxPageCount.Items.Count - 1;
									}
								}
								if (this.cbxPageCount.SelectedIndex != num2)
								{
									this.cbxPageCount.SelectedIndex = num2;
								}
								else
								{
									this.lvFamily.BeginUpdate();
									foreach (object obj2 in this.lvFamily.SelectedItems)
									{
										ListViewItem listViewItem2 = (ListViewItem)obj2;
										listViewItem2.Remove();
									}
									this.lvFamily.EndUpdate();
								}
								this.CurrentFamily = null;
								this.dgvType.DataSource = "";
								this.dgvType.ContextMenuStrip = null;
							}
						}
					}
					catch (Exception ex2)
					{
						MessageBox.Show(ex2.Message);
					}
				}
			}
		}

		private ListViewItem ListViewItemFromFamily(DbFamily family)
		{
			ListViewItem listViewItem = new ListViewItem();
			listViewItem.Text = family.Name;
			listViewItem.Tag = family;
			listViewItem.ImageKey = family.Name;
			ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
			listViewSubItem.Text = family.Version;
			listViewSubItem.Tag = Convert.ToInt64(family.Version);
			listViewItem.SubItems.Add(listViewSubItem);
			ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
			listViewSubItem2.Text = family.Date.ToString();
			listViewSubItem2.Tag = family.Date;
			listViewItem.SubItems.Add(listViewSubItem2);
			ListViewItem.ListViewSubItem listViewSubItem3 = new ListViewItem.ListViewSubItem();
			listViewSubItem3.Text = family.Database.CategoryTable[family.ParentId].Name;
			listViewSubItem3.Tag = family.Database.CategoryTable[family.ParentId];
			listViewItem.SubItems.Add(listViewSubItem3);
			ListViewItem.ListViewSubItem listViewSubItem4 = new ListViewItem.ListViewSubItem();
			listViewSubItem4.Text = family.Count.ToString();
			listViewSubItem4.Tag = family.Count;
			listViewItem.SubItems.Add(listViewSubItem4);
			ListViewItem.ListViewSubItem listViewSubItem5 = new ListViewItem.ListViewSubItem();
			if (family.UseDate.Ticks > 0L)
			{
				listViewSubItem5.Text = family.UseDate.ToString();
			}
			listViewSubItem5.Tag = family.UseDate;
			listViewItem.SubItems.Add(listViewSubItem5);
			ListViewItem.ListViewSubItem listViewSubItem6 = new ListViewItem.ListViewSubItem();
			listViewSubItem6.Text = family.Description;
			listViewSubItem6.Tag = family.Description;
			listViewItem.SubItems.Add(listViewSubItem6);
			return listViewItem;
		}

		private int ComputePageCount()
		{
			int count = this.mListFamilys.Count;
			int result;
			if (count < DlgMain.pageContainment)
			{
				result = count / DlgMain.pageContainment + 1;
			}
			else if (count % DlgMain.pageContainment > 0)
			{
				result = count / DlgMain.pageContainment + 1;
			}
			else
			{
				result = count / DlgMain.pageContainment;
			}
			return result;
		}

		private void trFamilyTree_MouseClick(object sender, MouseEventArgs e)
		{
			this.trCategory.ContextMenuStrip = null;
			TreeNode nodeAt = this.trCategory.GetNodeAt(e.X, e.Y);
			if (nodeAt.Level == 0)
			{
				this.trCategory.ContextMenuStrip = this.cmsSubject;
				return;
			}
			if (nodeAt.Tag is DbCategory)
			{
				this.trCategory.ContextMenuStrip = this.cmsCategory;
			}
		}

		private void btnAddCategory_Click(object sender, EventArgs e)
		{
			this.cmdAddCategory();
		}

		private void cmdAddCategory()
		{
			if (!this.IsServer)
			{
				this.doAddCategory();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddCategory())
				{
					this.doAddCategory();
					return;
				}
				MessageBox.Show("您的账号没有添加分类的权限。");
			}
		}

		private void doAddCategory()
		{
			if (this.trCategory.SelectedNode != null)
			{
				using (DlgAddCategory instance = DlgAddCategory.GetInstance(this))
				{
					instance.Activate();
					instance.ShowDialog(this);
					return;
				}
			}
			MessageBox.Show("请选择需添加分类的上级节点");
		}

		private void btnDelCategory_Click(object sender, EventArgs e)
		{
			if (this.trCategory.SelectedNode == null)
			{
				MessageBox.Show("请选择需删除的分类节点");
				return;
			}
			this.cmdDelCategory();
		}

		private void cmdDelCategory()
		{
			if (!this.IsServer)
			{
				this.doDelCategory();
				this.Recount();
				this.CurrentFamily = null;
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanDelCategory())
				{
					this.doDelCategory();
					this.Recount();
					this.CurrentFamily = null;
					return;
				}
				MessageBox.Show("您的账号没有删除分类的权限。");
			}
		}

		private void doDelCategory()
		{
			if (this.CurrentCategory != null && MessageBox.Show("确实要把选中的分类删除？", "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
				try
				{
					if (this.CurrentCategory.Remove(false))
					{
						this.CurrentFamily = null;
						this.trCategory.Nodes.Remove(this.trCategory.SelectedNode);
					}
					else
					{
						MessageBox.Show(this.CurrentCategory.Name + "删除失败", "族库管理");
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}

		public TreeNode FindRoot(TreeNode node)
		{
			if (node.Parent == null)
			{
				return node;
			}
			return this.FindRoot(node.Parent);
		}

		private void btnAddFamily_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
			this.Recount();
			this.mListFamilys = this.CurrentCategory.GetAllFamilies(false, this.checkType);
		}

		private void cmdAddFamily()
		{
			if (this.m_uiApp.ActiveUIDocument.Document.PathName == "")
			{
				MessageBox.Show("请先保存新建项目后再运行添加族功能", "盈建科提示");
				return;
			}
			if (!this.IsServer)
			{
				this.doAddFamily();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doAddFamily();
					return;
				}
				MessageBox.Show("您的账号没有添加族的权限。");
			}
		}

		private void doAddFamily()
		{
			if (!this.m_uiApp.ActiveUIDocument.Document.IsFamilyDocument)
			{
				using (DlgAddFamily instance = DlgAddFamily.GetInstance(this))
				{
					instance.Activate();
					instance.ShowDialog(this);
					return;
				}
			}
			MessageBox.Show("请在模型文档运行此命令。");
		}

		private void Recount()
		{
			string name = this.CurrentSubject.Name;
			TreeNode count = null;
			foreach (object obj in this.trCategory.Nodes)
			{
				TreeNode treeNode = (TreeNode)obj;
				if (treeNode.Text.Contains(name))
				{
					count = treeNode;
					break;
				}
			}
			if (this.CurrentCategory != null)
			{
				this.setCount(count);
				return;
			}
			long num = (long)this.CurrentSubject.Database.FamilyTable.Count(this.checkType);
			this.trCategory.SelectedNode.Text = this.CurrentSubject.ToString() + "(" + num.ToString() + ")";
			this.lvFamily.Items.Clear();
		}

		private void setCount(TreeNode tn)
		{
			if (tn.Tag is DbCategory)
			{
				tn.Text = ((DbCategory)tn.Tag).ToString();
				if (tn.Parent != null)
				{
					this.setCount(tn.Parent);
					return;
				}
			}
			else if (tn.Tag is DbSubject)
			{
				DbSubject dbSubject = (DbSubject)tn.Tag;
				long num;
				if (dbSubject.Database.Connection.State == ConnectionState.Closed)
				{
					dbSubject.Database.Open();
					num = (long)dbSubject.Database.FamilyTable.Count(this.checkType);
					dbSubject.Database.Close();
				}
				else
				{
					num = (long)dbSubject.Database.FamilyTable.Count(this.checkType);
				}
				tn.Text = dbSubject.ToString() + "(" + num.ToString() + ")";
			}
		}

		private void tsmiAddCategory_Click(object sender, EventArgs e)
		{
			this.doAddCategory();
		}

		private void tsmiDelCategory_Click(object sender, EventArgs e)
		{
			this.doDelCategory();
		}

		private void tsmiAddFamily_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
		}

		private void btnEditFamilyParam_Click(object sender, EventArgs e)
		{
			this.cmdEditFamily();
		}

		private void cmdEditFamily()
		{
			if (!this.IsServer)
			{
				this.doEditFamily();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanEditFamily())
				{
					this.doEditFamily();
					return;
				}
				MessageBox.Show("您的账号没有编辑族的权限。");
			}
		}

		private void doEditFamily()
		{
			if (!this.m_uiApp.ActiveUIDocument.Document.IsFamilyDocument)
			{
				if (this.lvFamily.SelectedItems.Count > 0)
				{
					using (DlgEditFamily instance = DlgEditFamily.GetInstance(this))
					{
						instance.Activate();
						if (instance.ShowDialog(this) != DialogResult.OK)
						{
							return;
						}
					}
					ListViewItem listViewItem = this.lvFamily.SelectedItems[0];
					listViewItem.Remove();
					DbFamily dbFamily = this.CurrentFamily;
					this.lvFamily.LargeImageList.Images.Add(dbFamily.Name + "e", dbFamily.Image);
					this.lvFamily.SmallImageList.Images.Add(dbFamily.Name + "e", dbFamily.Image);
					ListViewItem listViewItem2 = this.ListViewItemFromFamily(dbFamily);
					listViewItem2.ImageKey = dbFamily.Name + "e";
					this.lvFamily.Items.Add(listViewItem2);
					listViewItem2.Selected = true;
					this.lvFamily.Focus();
					return;
				}
			}
			else
			{
				MessageBox.Show("请在模型文档运行此命令。");
			}
		}

		private void trCategory_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
		{
			TreeNode node = e.Node;
			string text = node.Text;
			Regex regex = new Regex("^[0-9a-zA-Z一-龥]+$");
			if (!text.Equals(e.Label) && e.Label != null && e.Label.Trim() != "" && regex.IsMatch(e.Label) && node.Tag is DbCategory)
			{
				DbCategory dbCategory = (DbCategory)node.Tag;
				try
				{
					if (dbCategory.ReName(e.Label))
					{
						node.Text = e.Label;
					}
					else
					{
						node.Text = text;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
			e.CancelEdit = true;
			this.trCategory.LabelEdit = false;
		}

		private void trFamilyTree_AfterSelect(object sender, TreeViewEventArgs e)
		{
			this.CurrentFamily = null;
			TreeNode node = e.Node;
			if (node.Tag != null)
			{
				if (node.Tag is DbCategory)
				{
					this.CurrentSubject = (DbSubject)this.FindRoot(node).Tag;
					this.CurrentCategory = (DbCategory)node.Tag;
					this.CurrentFamily = null;
					return;
				}
				if (node.Tag is DbSubject)
				{
					this.CurrentSubject = (DbSubject)this.FindRoot(node).Tag;
					this.CurrentCategory = null;
					this.CurrentFamily = null;
				}
			}
		}

		private void doAddType()
		{
			this.boAdd = true;
			this.boEdit = false;
			this.dgvType.ReadOnly = false;
			this.dgvType.AllowUserToAddRows = true;
			this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.btnOk.Visible = true;
			this.btnCancel.Visible = true;
			this.lvFamily.Enabled = false;
			this.trackBar1.Enabled = false;
			this.trCategory.Enabled = false;
			this.btnAddCategory.Enabled = false;
			this.btnDelCategory.Enabled = false;
			this.btnAddFamily.Enabled = false;
			this.btnDelFamily.Enabled = false;
			this.btnEditCategory.Enabled = false;
			this.btnEditFamily.Enabled = false;
			this.btnAddType.Enabled = false;
			this.btnEditType.Enabled = false;
			this.btnDelType.Enabled = false;
			this.btnExpExcel.Enabled = false;
			this.btnTop.Enabled = false;
			this.btnPrevious.Enabled = false;
			this.btnNext.Enabled = false;
			this.btnBottom.Enabled = false;
			this.cbxPageCount.Enabled = false;
			this.btnExit.Enabled = false;
			this.btnDownload.Enabled = false;
			this.tsddbSearch.Enabled = false;
			this.tsddbTools.Enabled = false;
			this.btnPlace.Enabled = false;
			this.rbLocal.Enabled = false;
			this.rbUser.Enabled = false;
			this.rbServer.Enabled = false;
			base.ControlBox = false;
			for (int i = 0; i < this.dgvType.Rows.Count - 1; i++)
			{
                this.dgvType.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Gray;
				this.dgvType.Rows[i].ReadOnly = true;
			}
			this.addRowsNo = this.dgvType.Rows.Count;
			this.dgvType.ContextMenuStrip = this.cmsEditType;
			this.dgvType.Select();
		}

		private void btnAddType_Click(object sender, EventArgs e)
		{
			this.cmdAddType();
		}

		private void cmdAddType()
		{
			if (!this.IsServer)
			{
				this.doAddType();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddType())
				{
					this.doAddType();
					return;
				}
				MessageBox.Show("您的账号没有添加规格的权限。");
			}
		}

		private void btnDelFamily_Click(object sender, EventArgs e)
		{
			this.cmdDelFamily();
			this.mListFamilys = this.CurrentCategory.GetAllFamilies(false, this.checkType);
			this.lvFamily.Focus();
		}

		private void cmdLogin()
		{
			DlgLogin dlgLogin = new DlgLogin();
			if (dlgLogin.ShowDialog(this) == DialogResult.OK && dlgLogin.User != null)
			{
				dlgLogin.User.IncreaseCount();
				this.CurrentUser = dlgLogin.User;
				this.tsslCurrentUser.Text = "";
				this.toolStripStatusLabel2.Text = string.Format("当前登录用户：{0}", this.CurrentUser.Name);
				this.initPermission();
				this.tsLogout.Enabled = true;
			}
		}

		private void cmdDelFamily()
		{
			if (!this.IsServer)
			{
				this.doRemoveFamily();
				this.Recount();
				this.CurrentFamily = null;
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanDelFamily())
				{
					this.doRemoveFamily();
					this.Recount();
					this.CurrentFamily = null;
					return;
				}
				MessageBox.Show("您的账号没有删除族的权限。");
			}
		}

		private void doRemoveFamily()
		{
			if (this.lvFamily.SelectedItems.Count > 0 && MessageBox.Show("确定要删除选中的族？", "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
				this.lvFamily.BeginUpdate();
				foreach (object obj in this.lvFamily.SelectedItems)
				{
					ListViewItem listViewItem = (ListViewItem)obj;
					try
					{
						DbFamily dbFamily = (DbFamily)listViewItem.Tag;
						if (dbFamily.Remove(false))
						{
							listViewItem.Remove();
							this.btnAddType.Enabled = false;
							this.btnEditType.Enabled = false;
							this.btnDelType.Enabled = false;
							this.btnDelFamily.Enabled = false;
							this.btnEditFamily.Enabled = false;
							this.dgvType.DataSource = "";
							this.dgvType.ContextMenuStrip = null;
						}
						else
						{
							MessageBox.Show(dbFamily.Name + "删除失败!", "族库管理");
						}
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.Message);
					}
				}
				this.lvFamily.EndUpdate();
			}
		}

		private void tsmiDelFamily_Click(object sender, EventArgs e)
		{
			this.cmdDelFamily();
		}

		private void doEditType()
		{
			this.boAdd = false;
			this.boEdit = true;
			this.dgvType.ReadOnly = false;
			this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.btnOk.Visible = true;
			this.btnCancel.Visible = true;
			this.lvFamily.Enabled = false;
			this.trackBar1.Enabled = false;
			this.trCategory.Enabled = false;
			this.btnAddCategory.Enabled = false;
			this.btnDelCategory.Enabled = false;
			this.btnAddFamily.Enabled = false;
			this.btnDelFamily.Enabled = false;
			this.btnEditCategory.Enabled = false;
			this.btnEditFamily.Enabled = false;
			this.btnAddType.Enabled = false;
			this.btnEditType.Enabled = false;
			this.btnDelType.Enabled = false;
			this.btnExpExcel.Enabled = false;
			this.btnTop.Enabled = false;
			this.btnPrevious.Enabled = false;
			this.btnNext.Enabled = false;
			this.btnBottom.Enabled = false;
			this.cbxPageCount.Enabled = false;
			this.btnExit.Enabled = false;
			this.btnDownload.Enabled = false;
			this.tsddbSearch.Enabled = false;
			this.tsddbTools.Enabled = false;
			this.btnPlace.Enabled = false;
			this.rbLocal.Enabled = false;
			this.rbUser.Enabled = false;
			this.rbServer.Enabled = false;
			base.ControlBox = false;
			foreach (object obj in this.groupBox1.Controls)
			{
                System.Windows.Forms.Control control = (System.Windows.Forms.Control)obj;
				if (control is Button)
				{
					control.Enabled = false;
				}
			}
			foreach (object obj2 in this.groupBox2.Controls)
			{
                System.Windows.Forms.Control control2 = (System.Windows.Forms.Control)obj2;
				if (control2 is Button)
				{
					control2.Enabled = false;
				}
			}
			foreach (object obj3 in this.groupBox3.Controls)
			{
                System.Windows.Forms.Control control3 = (System.Windows.Forms.Control)obj3;
				if (control3 is Button)
				{
					control3.Enabled = false;
				}
			}
			this.dgvType.ContextMenuStrip = this.cmsEditType;
		}

		private void btnEditType_Click(object sender, EventArgs e)
		{
			this.cmdEditType();
		}

		private void cmdEditType()
		{
			if (!this.IsServer)
			{
				this.doEditType();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanEditType())
				{
					this.doEditType();
					return;
				}
				MessageBox.Show("您的账号没有删除规格的权限。");
			}
		}

		private void tsmiAddType_Click(object sender, EventArgs e)
		{
			this.doAddType();
		}

		private void tsmiEditType_Click(object sender, EventArgs e)
		{
			this.doEditType();
		}

		private void tsmiDelType_Click(object sender, EventArgs e)
		{
			this.doDelType();
		}

		private void doDelType()
		{
			if (this.dgvType.SelectedRows.Count > 0 && MessageBox.Show("确定要删除选定的规格？", "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
				DbFamily dbFamily = this.CurrentFamily;
				FamilyLibDatabase database = dbFamily.Database;
				ITypeTable typeTable = database.TypeTable;
				this.dgvType.Columns["TypeId"].Visible = true;
				foreach (object obj in this.dgvType.SelectedRows)
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					try
					{
						typeTable.Remove(Convert.ToInt32(dataGridViewRow.Cells["TypeId"].Value), dbFamily);
						this.dgvType.Rows.Remove(dataGridViewRow);
					}
					catch
					{
					}
				}
				this.dgvType.Columns["TypeId"].Visible = false;
			}
		}

		private void btnDelType_Click(object sender, EventArgs e)
		{
			this.cmdDelType();
		}

		private void cmdDelType()
		{
			if (!this.IsServer)
			{
				this.doDelType();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanDelType())
				{
					this.doDelType();
					return;
				}
				MessageBox.Show("您的账号没有删除规格的权限。");
			}
		}

		private void tsmiEditFamilyParams_Click(object sender, EventArgs e)
		{
			DlgEditFamily instance = DlgEditFamily.GetInstance(this);
			instance.Activate();
			instance.Show(this);
		}

		private void tsmiOutput_Click(object sender, EventArgs e)
		{
			if (this.trCategory.SelectedNode.Level != 0)
			{
				MessageBox.Show("请选中要导出的专业", "族库管理");
				return;
			}
			this.cmdExport(((DbSubject)this.trCategory.SelectedNode.Tag).Database);
		}

		private void tsmiInput_Click(object sender, EventArgs e)
		{
			this.cmdImport();
		}

		private void btnSelectType_Click(object sender, EventArgs e)
		{
		}

		private void btnOutput_Click(object sender, EventArgs e)
		{
		}

		private void cmdExport(FamilyLibDatabase db)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.FileName = this.getDbDefName(db);
			saveFileDialog.FilterIndex = 1;
			saveFileDialog.Filter = "族库(*.db)|*.db";
			saveFileDialog.OverwritePrompt = false;
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				int num = 0;
				if (db.Export(saveFileDialog.FileName, ref num))
				{
					MessageBox.Show("导出完成" + num + "个文件。", "族库管理");
				}
			}
		}

		private string getDbDefName(FamilyLibDatabase db)
		{
			int num = db.Name.LastIndexOf('\\');
			return db.Name.Substring(num + 1, db.Name.Length - num - 1);
		}

		private void cmdImport()
		{
			if (!this.IsServer)
			{
				this.doImport();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanImport())
				{
					this.doImport();
					return;
				}
				MessageBox.Show("您的账号没有导入族库的权限。");
			}
		}

		private void doImport()
		{
			try
			{
				OpenFileDialog openFileDialog = new OpenFileDialog();
				openFileDialog.FilterIndex = 1;
				openFileDialog.Filter = "族库(*.db)|*.db";
				if (openFileDialog.ShowDialog() == DialogResult.OK)
				{
					FamilyLibDatabase familyLibDatabase = new SqliteDatabase(openFileDialog.FileName);
					FamilyLibDatabase familyLibDatabase2 = null;
					foreach (FamilyLibDatabase familyLibDatabase3 in this.mFamilyDatabases)
					{
						if (familyLibDatabase3.SubjectTable.AllSubject()[0].Guid == familyLibDatabase.SubjectTable.AllSubject()[0].Guid)
						{
							familyLibDatabase2 = familyLibDatabase3;
							break;
						}
					}
					if (familyLibDatabase2 == null)
					{
						MessageBox.Show("请检查导入的族库文件，是否与目标分类一致。");
					}
					else
					{
						int num = 0;
						try
						{
							num = Convert.ToInt32(familyLibDatabase.SubjectTable.GetVersion());
						}
						catch
						{
						}
						int num2 = 0;
						try
						{
							num2 = Convert.ToInt32(familyLibDatabase2.SubjectTable.GetVersion());
						}
						catch
						{
						}
						if (num2 == 0)
						{
							familyLibDatabase2.SubjectTable.SetVersion(familyLibDatabase.SubjectTable.GetVersion());
						}
						else if (num2 < num)
						{
							MessageBox.Show("不能导入高版本族库。");
							return;
						}
						DlgCompare dlgCompare = new DlgCompare(familyLibDatabase2, familyLibDatabase);
						if (dlgCompare.ShowDialog() == DialogResult.OK)
						{
							int num3 = 0;
							if (familyLibDatabase2.Import(familyLibDatabase, dlgCompare.CategoryList, ref num3))
							{
								MessageBox.Show("导入完成" + num3 + "个文件。", "族库管理");
								FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, CheckType.All);
							}
							else
							{
								MessageBox.Show("导入被取消。", "族库管理");
							}
						}
					}
				}
			}
			catch
			{
				MessageBox.Show("请正确选择族库文件");
			}
		}

		private void cmdEditOk()
		{
			DbFamily dbFamily = this.CurrentFamily;
			FamilyLibDatabase database = dbFamily.Database;
			ITypeTable typeTable = database.TypeTable;
			try
			{
				typeTable.Update((DataTable)this.dgvType.DataSource, dbFamily);
				this.boEdit = false;
			}
			catch (Exception ex)
			{
				MessageBox.Show("修改发生异常。\n" + ex.Message, "族库管理");
			}
			finally
			{
				this.dgvType.DataSource = "";
				this.dgvType.DataSource = typeTable.DataTable(dbFamily);
				this.dgvType.Columns["TypeId"].Visible = false;
				this.dgvType.ReadOnly = true;
				this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
				this.btnExit.Enabled = true;
				base.ControlBox = true;
			}
		}

		private void cmdCancel()
		{
			this.boAdd = false;
			this.boEdit = false;
			this.btnOk.Visible = false;
			this.btnCancel.Visible = false;
			FamilyLibDatabase database = this.CurrentSubject.Database;
			DbCategory dbCategory = this.CurrentCategory;
			DbFamily family = this.CurrentFamily;
			ITypeTable typeTable = database.TypeTable;
			this.dgvType.AllowUserToAddRows = false;
			this.dgvType.DataSource = "";
			this.dgvType.DataSource = typeTable.DataTable(family);
			this.dgvType.Columns["TypeId"].Visible = false;
			this.dgvType.AllowUserToAddRows = false;
			this.dgvType.ReadOnly = true;
			this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvType.ContextMenuStrip = this.cmsType;
		}

		private void cmdAddOk()
		{
			try
			{
				DataTable dataTable = (DataTable)this.dgvType.DataSource;
				DataTable dataTable2 = dataTable.Copy();
				dataTable2.Rows.Clear();
				for (int i = this.addRowsNo - 1; i < dataTable.Rows.Count; i++)
				{
					dataTable2.ImportRow(dataTable.Rows[i]);
				}
				this.CurrentFamily.AddType(dataTable2);
				this.boAdd = false;
			}
			catch
			{
				MessageBox.Show("添加发生异常", "族库管理");
			}
			finally
			{
				this.dgvType.AllowUserToAddRows = false;
				this.dgvType.DataSource = "";
				this.dgvType.DataSource = this.CurrentFamily.Database.TypeTable.DataTable(this.CurrentFamily);
				this.dgvType.Columns["TypeId"].Visible = false;
				this.dgvType.AllowUserToAddRows = false;
				this.dgvType.ReadOnly = true;
				this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
				this.btnExit.Enabled = true;
				base.ControlBox = true;
			}
		}

		private void AddCategoryToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgAddCategory instance = DlgAddCategory.GetInstance(this);
			instance.Activate();
			instance.Show(this);
		}

		private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.dgvType.GetCellCount(DataGridViewElementStates.Selected) > 0)
			{
				try
				{
					Clipboard.Clear();
					Clipboard.SetDataObject(this.dgvType.GetClipboardContent());
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message.ToString());
				}
			}
		}

		private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
		{
			string text = Clipboard.GetText();
			if (string.IsNullOrEmpty(text))
			{
				MessageBox.Show("没有复制任何内容。");
				return;
			}
			string[] array = text.Trim().Split(new char[]
			{
				'\n'
			});
			int num = array.Length;
			if (num < 0)
			{
				return;
			}
			string[] array2 = array[0].Split(new char[]
			{
				'\t'
			});
			int num2 = array2.Length;
			DataTable dataTable = this.dgvType.DataSource as DataTable;
			DataRow dataRow = dataTable.NewRow();
			for (int i = 0; i < num2; i++)
			{
				string value = array2[i].Trim();
				dataRow[i + 1] = value;
			}
			dataTable.Rows.Add(dataRow);
			this.dgvType.DataSource = dataTable;
		}

		private void trFamilyTree_MouseDown(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				TreeNode nodeAt = this.trCategory.GetNodeAt(e.X, e.Y);
				if (nodeAt != null)
				{
					this.trCategory.SelectedNode = nodeAt;
				}
			}
		}

		private void ReNameToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.CurrentCategory.Limit)
			{
				MessageBox.Show("系统分类无法重命名", "族库管理");
				return;
			}
			this.trCategory.LabelEdit = true;
			this.trCategory.SelectedNode.BeginEdit();
		}

		private void trackBar1_Scroll(object sender, EventArgs e)
		{
			switch (this.trackBar1.Value)
			{
			case 0:
            this.lvFamily.View = System.Windows.Forms.View.Details;
				this.lvFamily.FullRowSelect = true;
				break;
			case 1:
                this.lvFamily.View = System.Windows.Forms.View.List;
				break;
			case 2:
                this.lvFamily.View = System.Windows.Forms.View.LargeIcon;
				break;
			}
			this.lvFamily.Select();
			this.lvFamily.Focus();
		}

		private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
		{
			ListView listView = sender as ListView;
			if (e.Column != (listView.ListViewItemSorter as DlgMain.ListViewColumnSorter).ColumnToSort)
			{
				(listView.ListViewItemSorter as DlgMain.ListViewColumnSorter).ColumnToSort = e.Column;
				(listView.ListViewItemSorter as DlgMain.ListViewColumnSorter).OrderOfSort = SortOrder.Ascending;
				return;
			}
			if ((listView.ListViewItemSorter as DlgMain.ListViewColumnSorter).OrderOfSort == SortOrder.Ascending)
			{
				(listView.ListViewItemSorter as DlgMain.ListViewColumnSorter).OrderOfSort = SortOrder.Descending;
				return;
			}
			(listView.ListViewItemSorter as DlgMain.ListViewColumnSorter).OrderOfSort = SortOrder.Ascending;
		}

		private void listView1_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count == 1)
			{
				this.CurrentFamily = (DbFamily)this.lvFamily.SelectedItems[0].Tag;
				this.btnEditFamily.Enabled = true;
				return;
			}
			this.btnEditFamily.Enabled = false;
		}

		public void ShowType()
		{
			this.dgvType.DataSource = null;
			DataTable dataTable = this.CurrentFamily.Database.TypeTable.DataTable(this.CurrentFamily);
			if (dataTable != null)
			{
				this.dgvType.DataSource = dataTable;
				this.dgvType.Columns["TypeId"].Visible = false;
				this.dgvType.AutoResizeColumns();
				this.dgvType.AllowUserToResizeColumns = true;
			}
		}

		private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
		{
			string text = this.lvFamily.Items[e.Item].Text;
			if (this.lvFamily.Items[e.Item].Tag is DbFamily && e.Label != null && e.Label != "" && !text.Equals(e.Label))
			{
				DbFamily dbFamily = (DbFamily)this.lvFamily.Items[e.Item].Tag;
				if (dbFamily.Rename(e.Label))
				{
					this.lvFamily.Items[e.Item].Text = e.Label;
				}
				else
				{
					this.lvFamily.Items[e.Item].Text = text;
				}
			}
			e.CancelEdit = true;
			this.lvFamily.LabelEdit = false;
		}

		private void tsmAbout(object sender, EventArgs e)
		{
			AboutBox1 aboutBox = new AboutBox1();
			aboutBox.Show();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			DataTable dataTable = (DataTable)this.dgvType.DataSource;
			char[] array = new char[]
			{
				'\\',
				':',
				'{',
				'}',
				'[',
				']',
				'|',
				';',
				'<',
				'>',
				'?',
				'\'',
				'~',
				'`'
			};
			if (this.boAdd)
			{
				for (int i = this.addRowsNo - 1; i < dataTable.Rows.Count; i++)
				{
					string source = dataTable.Rows[i][1].ToString();
					foreach (char c in array)
					{
						if (source.Contains(c))
						{
							MessageBox.Show("规格名称不能包含以下字符： " + c);
							foreach (object obj in this.dgvType.SelectedRows)
							{
								DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
								dataGridViewRow.Selected = false;
							}
							this.dgvType.Rows[i].Cells[1].Selected = true;
							return;
						}
					}
				}
			}
			else if (this.boEdit)
			{
				for (int k = 0; k < dataTable.Rows.Count; k++)
				{
					string source2 = dataTable.Rows[k][1].ToString();
					foreach (char c2 in array)
					{
						if (source2.Contains(c2))
						{
							MessageBox.Show("规格名称不能包含以下字符： " + c2);
							foreach (object obj2 in this.dgvType.SelectedRows)
							{
								DataGridViewRow dataGridViewRow2 = (DataGridViewRow)obj2;
								dataGridViewRow2.Selected = false;
							}
							this.dgvType.Rows[k].Cells[1].Selected = true;
							return;
						}
					}
				}
			}
			try
			{
				if (this.boAdd)
				{
					this.cmdAddOk();
				}
				else if (this.boEdit)
				{
					this.cmdEditOk();
				}
			}
			catch
			{
			}
			this.btnOk.Visible = false;
			this.btnCancel.Visible = false;
			this.lvFamily.Enabled = true;
			this.trackBar1.Enabled = true;
			this.trCategory.Enabled = true;
			this.btnEditCategory.Enabled = true;
			this.btnAddCategory.Enabled = true;
			this.btnDelCategory.Enabled = true;
			this.btnExpExcel.Enabled = true;
			this.btnAddFamily.Enabled = true;
			this.btnDelFamily.Enabled = true;
			this.btnEditCategory.Enabled = true;
			this.btnEditFamily.Enabled = true;
			this.btnAddType.Enabled = true;
			this.btnEditType.Enabled = true;
			this.btnDelType.Enabled = true;
			this.btnDownload.Enabled = true;
			this.tsddbSearch.Enabled = true;
			this.tsddbTools.Enabled = true;
			this.btnPlace.Enabled = true;
			this.rbLocal.Enabled = true;
			this.rbUser.Enabled = true;
			this.rbServer.Enabled = true;
			if (this.cbxPageCount.SelectedIndex == 0)
			{
				this.btnTop.Enabled = false;
				this.btnPrevious.Enabled = false;
			}
			else
			{
				this.btnTop.Enabled = true;
				this.btnPrevious.Enabled = true;
			}
			if (this.cbxPageCount.SelectedIndex == this.cbxPageCount.Items.Count - 1)
			{
				this.btnNext.Enabled = false;
				this.btnBottom.Enabled = false;
			}
			else
			{
				this.btnNext.Enabled = true;
				this.btnBottom.Enabled = true;
			}
			this.cbxPageCount.Enabled = true;
			this.dgvType.ContextMenuStrip = this.cmsType;
			if (this.dgvType.SelectedRows.Count > 0)
			{
				this.btnDelType.Enabled = true;
				this.btnEditType.Enabled = true;
				return;
			}
			this.btnDelType.Enabled = false;
			this.btnEditType.Enabled = false;
		}

		private void inputToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdImport();
		}

		private void outputToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdExport();
		}

		private void exitToolStripMenuItem_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void helpToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void groupBox3_Enter(object sender, EventArgs e)
		{
		}

		private void btnAddOk_Click(object sender, EventArgs e)
		{
		}

		private void btnAddCancel_Click(object sender, EventArgs e)
		{
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.cmdCancel();
			this.lvFamily.Enabled = true;
			this.trackBar1.Enabled = true;
			this.trCategory.Enabled = true;
			this.btnAddCategory.Enabled = true;
			this.btnDelCategory.Enabled = true;
			this.btnAddFamily.Enabled = true;
			this.btnDelFamily.Enabled = true;
			this.btnEditCategory.Enabled = true;
			this.btnEditFamily.Enabled = true;
			this.btnAddType.Enabled = true;
			this.btnEditType.Enabled = true;
			this.btnDelType.Enabled = true;
			this.btnExpExcel.Enabled = true;
			this.btnEditCategory.Enabled = true;
			this.btnExit.Enabled = true;
			this.btnDownload.Enabled = true;
			this.tsddbSearch.Enabled = true;
			this.tsddbTools.Enabled = true;
			this.btnPlace.Enabled = true;
			this.rbLocal.Enabled = true;
			this.rbUser.Enabled = true;
			this.rbServer.Enabled = true;
			base.ControlBox = true;
			if (this.cbxPageCount.SelectedIndex == 0)
			{
				this.btnTop.Enabled = false;
				this.btnPrevious.Enabled = false;
			}
			else
			{
				this.btnTop.Enabled = true;
				this.btnPrevious.Enabled = true;
			}
			if (this.cbxPageCount.SelectedIndex == this.cbxPageCount.Items.Count - 1)
			{
				this.btnNext.Enabled = false;
				this.btnBottom.Enabled = false;
			}
			else
			{
				this.btnNext.Enabled = true;
				this.btnBottom.Enabled = true;
			}
			this.cbxPageCount.Enabled = true;
			if (this.dgvType.SelectedRows.Count > 0)
			{
				this.btnDelType.Enabled = true;
				this.btnEditType.Enabled = true;
				return;
			}
			this.btnDelType.Enabled = false;
			this.btnEditType.Enabled = false;
		}

		private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
		{
		}

		private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
		{
			AboutBox1 aboutBox = new AboutBox1();
			aboutBox.Show();
		}

		private void AddTypeToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdAddType();
		}

		private void RemoveTypeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdDelType();
		}

		private void EditTypeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdEditType();
		}

		private void addCategoryToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdAddCategory();
		}

		private void removeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdDelCategory();
		}

		private void AddFamilyToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
		}

		private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdDelFamily();
		}

		private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdEditFamily();
		}

		private void addFamilyToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
			this.Recount();
		}

		private void 添加分类ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.doAddCategory();
		}

		private void 重命名ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count > 0)
			{
				if (this.CurrentFamily.Limit)
				{
					MessageBox.Show("系统族无法重命名", "族库管理");
					return;
				}
				this.lvFamily.LabelEdit = true;
				this.lvFamily.SelectedItems[0].BeginEdit();
			}
		}

		private void btnEditCategoryParam_Click(object sender, EventArgs e)
		{
			if (this.trCategory.SelectedNode == null)
			{
				MessageBox.Show("请选择需编辑的分类节点");
				return;
			}
			this.cmdEditCategory();
		}

		private void cmdEditCategory()
		{
			if (!this.IsServer)
			{
				this.doEditCategory();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanEditCategory())
				{
					this.doEditCategory();
					return;
				}
				MessageBox.Show("您的账号没有编辑分类的权限。");
			}
		}

		private void doEditCategory()
		{
			using (DlgEditCategory instance = DlgEditCategory.GetInstance(this))
			{
				instance.Activate();
				instance.ShowDialog(this);
			}
		}

		private void editCategoryToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdEditCategory();
		}

		private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdExport();
		}

		private void cmdExport()
		{
			if (!this.IsServer)
			{
				this.doExport();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanExport())
				{
					this.doExport();
					return;
				}
				MessageBox.Show("您的账号没有导出族库的权限。");
			}
		}

		private void doExport()
		{
			if (this.trCategory.SelectedNode == null)
			{
				MessageBox.Show("请选中要导出的专业", "族库管理");
				return;
			}
			this.cmdExport(this.CurrentSubject.Database);
		}

		private void 导入ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdImport();
		}

		private void dgvType_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void 登陆服务器ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void 服务器ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void 本地族库ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void dgvType_SortCompare_1(object sender, DataGridViewSortCompareEventArgs e)
		{
			double num;
			double.TryParse(e.CellValue1.ToString().Trim(), out num);
			double num2;
			double.TryParse(e.CellValue2.ToString().Trim(), out num2);
			if (num < num2)
			{
				e.SortResult = -1;
			}
			else if (num == num2)
			{
				e.SortResult = 0;
			}
			else
			{
				e.SortResult = 1;
			}
			e.Handled = true;
		}

		private void dgvType_Sorted(object sender, EventArgs e)
		{
		}

		private void button1_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void cbxPageCount_SelectedIndexChanged(object sender, EventArgs e)
		{
			try
			{
				this.btnTop.Enabled = true;
				this.btnPrevious.Enabled = true;
				this.btnNext.Enabled = true;
				this.btnBottom.Enabled = true;
				if (this.cbxPageCount.SelectedIndex == 0)
				{
					this.btnTop.Enabled = false;
					this.btnPrevious.Enabled = false;
				}
				else
				{
					this.btnTop.Enabled = true;
					this.btnPrevious.Enabled = true;
				}
				if (this.cbxPageCount.SelectedIndex == this.cbxPageCount.Items.Count - 1)
				{
					this.btnNext.Enabled = false;
					this.btnBottom.Enabled = false;
				}
				else
				{
					this.btnNext.Enabled = true;
					this.btnBottom.Enabled = true;
				}
				this.lvFamily.Items.Clear();
				this.lvFamily.LargeImageList.Images.Clear();
				this.lvFamily.SmallImageList.Images.Clear();
				int num = Convert.ToInt32(this.cbxPageCount.SelectedItem);
				this.lvFamily.BeginUpdate();
				int num2 = (num - 1) * DlgMain.pageContainment;
				while (num2 < num * DlgMain.pageContainment && num2 < this.mListFamilys.Count)
				{
					DbFamily dbFamily = this.mListFamilys[num2];
					this.lvFamily.LargeImageList.Images.Add(dbFamily.Name, dbFamily.Image);
					this.lvFamily.SmallImageList.Images.Add(dbFamily.Name, dbFamily.Image);
					ListViewItem value = this.ListViewItemFromFamily(dbFamily);
					this.lvFamily.Items.Add(value);
					num2++;
				}
				this.lvFamily.EndUpdate();
				this.lvFamily.Focus();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void button3_Click(object sender, EventArgs e)
		{
			if (this.cbxPageCount.SelectedIndex != 0)
			{
				this.cbxPageCount.SelectedIndex--;
			}
			this.lvFamily.Focus();
		}

		private void button4_Click(object sender, EventArgs e)
		{
			if (this.cbxPageCount.SelectedIndex < this.cbxPageCount.Items.Count - 1)
			{
				this.cbxPageCount.SelectedIndex++;
			}
			this.lvFamily.Focus();
		}

		private void button2_Click(object sender, EventArgs e)
		{
			this.cbxPageCount.SelectedIndex = 0;
			this.lvFamily.Focus();
		}

		private void button5_Click(object sender, EventArgs e)
		{
			this.cbxPageCount.SelectedIndex = this.cbxPageCount.Items.Count - 1;
			this.lvFamily.Focus();
		}

		private void dgvType_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
			MessageBox.Show("输入的格式不正确，请检查后重新输入。");
		}

		private void dgvType_SelectionChanged(object sender, EventArgs e)
		{
			if (this.boAdd || this.boEdit)
			{
				return;
			}
			if (this.dgvType.SelectedRows.Count > 0)
			{
				this.btnDelType.Enabled = true;
				this.btnEditType.Enabled = true;
				this.btnPlace.Visible = true;
				return;
			}
			this.btnDelType.Enabled = false;
			this.btnEditType.Enabled = false;
			this.btnPlace.Visible = false;
		}

		private void 加载ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Document document = this.m_uiApp.ActiveUIDocument.Document;
			UIDocument activeUIDocument = this.m_uiApp.ActiveUIDocument;
			Family family = this.CurrentFamily.Load(document);
			try
			{
				if (family.Document.PathName == document.PathName)
				{
					MessageBox.Show("加载完成。");
				}
				else
				{
					MessageBox.Show("加载失败。");
				}
			}
			catch
			{
				MessageBox.Show("加载失败。");
			}
		}

		private void toolStripButton1_Click(object sender, EventArgs e)
		{
		}

		private void tstbSearchName_Enter(object sender, EventArgs e)
		{
		}

		private void tstbSearchName_Click(object sender, EventArgs e)
		{
		}

		private void tstbSearchName_KeyDown(object sender, KeyEventArgs e)
		{
		}

		private void tsmiUserPath_Click(object sender, EventArgs e)
		{
			UserDbData userDbData = ConfigUtils.ReadFamilyLibXmlFile("User", this.m_uiApp.Application.VersionNumber) as UserDbData;
			using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
			{
				if (userDbData != null)
				{
					folderBrowserDialog.SelectedPath = userDbData.DatabasePath;
				}
				if (folderBrowserDialog.ShowDialog() != DialogResult.OK)
				{
					return;
				}
				if (string.IsNullOrEmpty(folderBrowserDialog.SelectedPath))
				{
					return;
				}
				this.userPath = folderBrowserDialog.SelectedPath;
			}
			List<FamilyLibDatabase> userDbs = FamilyLibDatabase.GetUserDbs(this.userPath, this.m_uiApp.Application.VersionNumber);
			if (userDbs.Count < 5)
			{
				byte[] pReadByte = Resource1.ResourceManager.GetObject("Architecture") as byte[];
				Assist.FileUtil.WriteFile(pReadByte, this.userPath + "\\Architecture" + this.m_uiApp.Application.VersionNumber + ".db");
				byte[] pReadByte2 = Resource1.ResourceManager.GetObject("Electric") as byte[];
				Assist.FileUtil.WriteFile(pReadByte2, this.userPath + "\\Electric" + this.m_uiApp.Application.VersionNumber + ".db");
				byte[] pReadByte3 = Resource1.ResourceManager.GetObject("Plumbing") as byte[];
				Assist.FileUtil.WriteFile(pReadByte3, this.userPath + "\\Plumbing" + this.m_uiApp.Application.VersionNumber + ".db");
				byte[] pReadByte4 = Resource1.ResourceManager.GetObject("HVAC") as byte[];
				Assist.FileUtil.WriteFile(pReadByte4, this.userPath + "\\HVAC" + this.m_uiApp.Application.VersionNumber + ".db");
				byte[] pReadByte5 = Resource1.ResourceManager.GetObject("System") as byte[];
				Assist.FileUtil.WriteFile(pReadByte5, this.userPath + "\\System" + this.m_uiApp.Application.VersionNumber + ".db");
			}
			UserDbData data = new UserDbData(this.userPath);
			ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "族库类型", data);
		}

		private void tsmiServer_Click(object sender, EventArgs e)
		{
		}

		private void rbLocal_CheckedChanged(object sender, EventArgs e)
		{
			if (((RadioButton)sender).Checked)
			{
				this.SelectDb();
			}
		}

		private void SelectDb()
		{
			if (this.rbLocal.Checked)
			{
				try
				{
					this.mFamilyDatabases = FamilyLibDatabase.GetLocalDbs(this.m_uiApp.Application.VersionNumber);
					if (this.mFamilyDatabases.Count < 5)
					{
						MessageBox.Show("\n没有检测到本地族库，请安装族库。");
						this.rbLocal.Checked = false;
						base.Close();
					}
					FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, this.checkType);
					this.lvFamily.Items.Clear();
					this.dgvType.DataSource = null;
					this.IsServer = false;
					this.btnDownload.Visible = false;
					this.tsddbLogin.Enabled = false;
					this.tsddbCommunication.Visible = false;
					this.rbTemp = this.rbLocal;
					this.CurrentCategory = null;
					this.CurrentSubject = null;
					this.CurrentFamily = null;
					this.timer1.Enabled = false;
					this.tsmiPL.Visible = false;
					LocalDbData data = new LocalDbData("");
					ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "族库类型", data);
					this.mListFamilys.Clear();
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
					return;
				}
			}
			if (this.rbUser.Checked)
			{
				try
				{
					this.tsddbLogin.Enabled = false;
					UserDbData userDbData = ConfigUtils.ReadUserData("族库类型", this.m_uiApp.Application.VersionNumber) as UserDbData;
					if (userDbData.DatabasePath == "")
					{
						MessageBox.Show("请先打开‘设置’功能设置用户族库路径。");
						if (this.rbTemp != null)
						{
							this.rbTemp.Checked = true;
						}
					}
					else
					{
						ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "族库类型", userDbData);
						this.mFamilyDatabases = FamilyLibDatabase.GetDbs(this.m_uiApp.Application.VersionNumber);
						FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, this.checkType);
						this.lvFamily.Items.Clear();
						this.dgvType.DataSource = null;
						this.IsServer = false;
						this.btnDownload.Visible = false;
						this.tsddbLogin.Enabled = false;
						this.tsddbCommunication.Enabled = false;
						this.rbTemp = this.rbUser;
						this.CurrentCategory = null;
						this.CurrentSubject = null;
						this.CurrentFamily = null;
						this.tsmiPL.Visible = false;
						this.mListFamilys.Clear();
					}
				}
				catch (Exception ex2)
				{
					MessageBox.Show(ex2.Message);
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
					return;
				}
			}
			if (this.rbServer.Checked)
			{
				try
				{
					string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
					string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "Server", "value");
					if (dataFromConfigFile == "")
					{
						MessageBox.Show("请先运行‘服务器连接配置’命令配置服务器。");
						this.rbTemp.Checked = true;
					}
					else
					{
						ServerDbData data2 = new ServerDbData("", "", "");
						ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "族库类型", data2);
						foreach (FamilyLibDatabase familyLibDatabase in this.mFamilyDatabases)
						{
							familyLibDatabase.Close();
						}
						this.mFamilyDatabases = FamilyLibDatabase.GetDbs(this.m_uiApp.Application.VersionNumber);
						if (this.mFamilyDatabases.Count < 5)
						{
							MessageBox.Show("\n族库服务器没有正确配置数据库，请联系数据库管理员。");
							this.rbLocal.Checked = true;
							return;
						}
						FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, this.checkType);
						this.lvFamily.Items.Clear();
						this.dgvType.DataSource = null;
						this.btnDownload.Visible = true;
						this.IsServer = true;
						this.tsddbLogin.Enabled = true;
						this.autoLogin();
						this.rbTemp = this.rbServer;
						this.CurrentCategory = null;
						this.CurrentSubject = null;
						this.CurrentFamily = null;
						this.timer1.Enabled = true;
						this.tsmiPL.Visible = true;
						this.mListFamilys.Clear();
					}
				}
				catch
				{
					MessageBox.Show("无法连接到服务器，请检查网络是否畅通。");
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
					return;
				}
			}
			if (this.rbCompany.Checked)
			{
				try
				{
					string fileName2 = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
					string dataFromConfigFile2 = XmlUtils.GetDataFromConfigFile(fileName2, "Server", "value");
					if (dataFromConfigFile2 == "")
					{
						MessageBox.Show("请先运行‘服务器连接配置’命令配置服务器。");
						this.rbTemp.Checked = true;
					}
					else
					{
						CompanyDbData data3 = new CompanyDbData("", "", "");
						ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "族库类型", data3);
						foreach (FamilyLibDatabase familyLibDatabase2 in this.mFamilyDatabases)
						{
							familyLibDatabase2.Close();
						}
						this.mFamilyDatabases = FamilyLibDatabase.GetDbs(this.m_uiApp.Application.VersionNumber);
						if (this.mFamilyDatabases.Count < 1)
						{
							MessageBox.Show("\n族库服务器没有正确配置数据库，请联系数据库管理员。");
							this.rbLocal.Checked = true;
							return;
						}
						FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, this.checkType);
						this.lvFamily.Items.Clear();
						this.dgvType.DataSource = null;
						this.btnDownload.Visible = false;
						this.IsServer = true;
						this.tsddbLogin.Enabled = true;
						this.autoLogin();
						this.rbTemp = this.rbCompany;
						this.CurrentCategory = null;
						this.CurrentSubject = null;
						this.CurrentFamily = null;
						this.timer1.Enabled = true;
						this.tsmiPL.Visible = true;
						this.mListFamilys.Clear();
					}
				}
				catch
				{
					MessageBox.Show("无法连接到服务器，请检查网络是否畅通。");
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
					return;
				}
			}
			try
			{
				FamilyLibDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(SubjectType.MyCollect, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase.FillTree(sqliteDB, this.trCategory, CheckType.All);
				this.mFamilyDatabases.Add(sqliteDB);
			}
			catch (Exception ex3)
			{
				ex3.ToString();
			}
		}

		private void rbUser_CheckedChanged(object sender, EventArgs e)
		{
			if (((RadioButton)sender).Checked)
			{
				this.SelectDb();
			}
		}

		private void rbServer_CheckedChanged(object sender, EventArgs e)
		{
			if (((RadioButton)sender).Checked)
			{
				this.SelectDb();
			}
		}

		private void rdCompany_CheckedChanged(object sender, EventArgs e)
		{
			if (((RadioButton)sender).Checked)
			{
				this.SelectDb();
			}
		}

		private void autoLogin()
		{
			if (!DlgLogin.IsAutoLogin())
			{
				return;
			}
			string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
			string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "AutoUser", "value");
			DbUser user = DbUser.GetUser(dataFromConfigFile, BimServerDB.Default);
			if (user == null)
			{
				return;
			}
			string dataFromConfigFile2 = XmlUtils.GetDataFromConfigFile(fileName, "AutoPwd", "value");
			if (!user.Password.Equals(DbUser.ToMd5(dataFromConfigFile2)))
			{
				this.toolStripStatusLabel2.Text = string.Format("当前登录用户：{0}", this.CurrentUser.Name);
				this.tsLogout.Enabled = true;
				return;
			}
			this.CurrentUser = user;
			user.IncreaseCount();
			this.tsslCurrentUser.Text = "";
			this.toolStripStatusLabel2.Text = string.Format("当前登录用户：{0}", this.CurrentUser.Name);
			this.initPermission();
			this.tsLogout.Enabled = true;
		}

		private void doAddFamily(DbCategory category, DbFamily family, FileInfo fi, Document doc, Family fam, ref int count)
		{
			try
			{
				if (category.AddFamily(family, fi))
				{
					count++;
					family.RecordTypes(this.UiApp.ActiveUIDocument.Document, category.Database, fi.FullName);
					this.lvFamily.LargeImageList.Images.Add(family.Name, family.Image);
					this.lvFamily.SmallImageList.Images.Add(family.Name, family.Image);
					ListViewItem value = this.ListViewItemFromFamily(family);
					this.lvFamily.Items.Add(value);
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private bool CreateCategoryByFolder(DbCategory category, DirectoryInfo rootDir, ProgressBarForm myProgress, ref int count, ExceptionInfo info)
		{
			bool flag = false;
			foreach (FileInfo fileInfo in rootDir.GetFiles())
			{
				if (fileInfo.Extension == ".rfa")
				{
					try
					{
						string fullName = fileInfo.FullName;
						PictureBox pictureBox = new PictureBox();
						new PictureBox();
						PictureBox pictureBox2 = new PictureBox();
						ListBox listBox = new ListBox();
						ListBox listBox2 = new ListBox();
						int length = fileInfo.Name.LastIndexOf(".");
						string name = fileInfo.Name.Substring(0, length);
						if (!FamilyUtil.CanOpenDocument(this.UiApp, fullName))
						{
							info.AddVersionException(name, fullName);
						}
						else
						{
							FamilyUtil.GetFamilyPreview(this.UiApp, fullName, pictureBox);
							pictureBox2.Image = FamilyUtil.GetLargeImage(this.UiApp.Application, fullName);
							FamilyUtil.GetFamilyTypeParams(this.UiApp, fullName, listBox2, category);
							FamilyUtil.GetFamilyInstanceParams(this.UiApp, fullName, listBox, listBox2);
							List<DbParamDefinition> paramDefinitionList = category.GetParamDefinitionList();
							foreach (DbParamDefinition dbParamDefinition in paramDefinitionList)
							{
								bool flag2 = false;
								foreach (object obj in listBox2.Items)
								{
									DbParamDefinition dbParamDefinition2 = (DbParamDefinition)obj;
									if (dbParamDefinition2.Name == dbParamDefinition.Name)
									{
										flag2 = true;
										break;
									}
								}
								if (!flag2)
								{
									info.AddParamException(name, fullName);
								}
							}
							Document document = this.UiApp.ActiveUIDocument.Document;
							Family family = FamilyUtil.ReloadFamily(document, fileInfo.FullName);
							DbFamily dbFamily = category.Database.FamilyTable[family.Name];
							if (dbFamily != null)
							{
								info.AddNameException(name, fullName);
							}
							else
							{
								DbFamily dbFamily2 = new DbFamily(name, pictureBox.Image);
								dbFamily2.Version = this.UiApp.Application.VersionNumber;
								dbFamily2.SetDate(DateTime.Now);
								foreach (object obj2 in listBox.Items)
								{
									DbParamDefinition item = (DbParamDefinition)obj2;
									dbFamily2.ParamDefinitionList.Add(item);
								}
								foreach (object obj3 in listBox2.Items)
								{
									DbParamDefinition item2 = (DbParamDefinition)obj3;
									dbFamily2.ParamDefinitionList.Add(item2);
								}
								dbFamily2.Description = "";
								dbFamily2.Name = name;
								if (pictureBox2.Image == null)
								{
									dbFamily2.LargeImage = Resource1._null;
								}
								else
								{
									dbFamily2.LargeImage = pictureBox2.Image;
								}
								dbFamily2.TwoDImage = Resource1._null;
								this.doAddFamily(category, dbFamily2, fileInfo, document, family, ref count);
								if (!myProgress.ProgressStep(1) && myProgress.IsStoped)
								{
									myProgress.Dispose();
									MessageBox.Show("中断操作！");
									flag = true;
									return flag;
								}
							}
						}
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.Message);
					}
				}
			}
			DirectoryInfo[] directories = rootDir.GetDirectories();
			int j = 0;
			while (j < directories.Length)
			{
				DirectoryInfo directoryInfo = directories[j];
				DbCategory category2 = new DbCategory(directoryInfo.Name);
				try
				{
					category.AddCategory(category2);
				}
				catch (Exception)
				{
					Dictionary<string, string> dictionary = new Dictionary<string, string>();
					this.FindFiles(directoryInfo, dictionary);
					foreach (string text in dictionary.Keys)
					{
						info.AddCategoryException(dictionary[text], text);
					}
					goto IL_3D9;
				}
				goto IL_3C1;
				IL_3D9:
				j++;
				continue;
				IL_3C1:
				flag = this.CreateCategoryByFolder(category2, directoryInfo, myProgress, ref count, info);
				if (flag)
				{
					return flag;
				}
				goto IL_3D9;
			}
			return flag;
		}

		private bool CreateCategoryByFolder(DbSubject subject, DirectoryInfo rootDir, ProgressBarForm myProgress, ref int count, ExceptionInfo info)
		{
			bool flag = false;
			DirectoryInfo[] directories = rootDir.GetDirectories();
			int i = 0;
			while (i < directories.Length)
			{
				DirectoryInfo directoryInfo = directories[i];
				DbCategory category = new DbCategory(directoryInfo.Name);
				try
				{
					subject.AddCategory(category);
				}
				catch (Exception)
				{
					Dictionary<string, string> dictionary = new Dictionary<string, string>();
					this.FindFiles(directoryInfo, dictionary);
					foreach (string text in dictionary.Keys)
					{
						info.AddCategoryException(dictionary[text], text);
					}
					goto IL_98;
				}
				goto IL_82;
				IL_98:
				i++;
				continue;
				IL_82:
				flag = this.CreateCategoryByFolder(category, directoryInfo, myProgress, ref count, info);
				if (flag)
				{
					return flag;
				}
				goto IL_98;
			}
			return flag;
		}

		private void FindCategoryByFolder(DirectoryInfo rootDir, ref int findCount)
		{
			foreach (FileInfo fileInfo in rootDir.GetFiles())
			{
				if (fileInfo.Extension == ".rfa")
				{
					findCount++;
				}
			}
			foreach (DirectoryInfo rootDir2 in rootDir.GetDirectories())
			{
				this.FindCategoryByFolder(rootDir2, ref findCount);
			}
		}

		private void FindCategoryBySubjectFolder(DirectoryInfo rootDir, ref int findCount)
		{
			foreach (DirectoryInfo rootDir2 in rootDir.GetDirectories())
			{
				this.FindCategoryByFolder(rootDir2, ref findCount);
			}
		}

		private Dictionary<string, string> FindFiles(DirectoryInfo rootDir, Dictionary<string, string> dic)
		{
			foreach (FileInfo fileInfo in rootDir.GetFiles())
			{
				if (fileInfo.Extension == ".rfa")
				{
					dic.Add(fileInfo.FullName, fileInfo.Name);
				}
			}
			foreach (DirectoryInfo rootDir2 in rootDir.GetDirectories())
			{
				this.FindFiles(rootDir2, dic);
			}
			return dic;
		}

		private string getParamValue(Document doc, Parameter param)
		{
			string result = "";
            switch ((int)param.StorageType)
			{
			case 1:
				result = 0.ToString();
				try
				{
					result = param.AsInteger().ToString();
                    if ((int)param.DisplayUnitType != -2)
					{
						result = ((double)param.AsInteger() * Convert.ToDouble(UnitConvertC.ImperialDutRatio(param.DisplayUnitType))).ToString();
					}
					return result;
				}
				catch
				{
					return result;
				}
				goto Block_5;
			case 2:
				result = 0.0.ToString();
				try
				{
                    if ((int)param.DisplayUnitType != -2)
					{
						result = Math.Round(param.AsDouble() * Convert.ToDouble(UnitConvertC.ImperialDutRatio(param.DisplayUnitType)), 1).ToString();
					}
					else
					{
						result = Math.Round(param.AsDouble(), 1).ToString();
					}
					return result;
				}
				catch
				{
					return result;
				}
				break;
			case 3:
				goto IL_F6;
			case 4:
				break;
			default:
				return result;
			}
			ElementId id = param.AsElementId();
			Element element = RevitVersionFuncs.GetElement(doc, id);
			if (element != null)
			{
				return element.Name;
			}
			return result;
			Block_5:
				IL_F6:
			try
			{
				result = param.AsString();
			}
			catch
			{
			}
			return result;
		}

		private void recordFamily(Document doc, FamilyLibDatabase db, DbFamily dbFamily, string fileName)
		{
			Family family = FamilyUtil.LoadFamily(this.m_uiApp.ActiveUIDocument.Document, fileName);
			DataTable dataTable = db.TypeTable.DataTable(dbFamily);
			foreach (FamilySymbol familySymbol in family.GetSymbols())
			{
				DataRow dataRow = dataTable.NewRow();
				dataRow["规格名"] = familySymbol.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString();
				foreach (object obj in dataTable.Columns)
				{
					DataColumn dataColumn = (DataColumn)obj;
					Parameter parameter = familySymbol.GetParameter(dataColumn.ColumnName);
					if (parameter != null && !parameter.IsReadOnly)
					{
						dataRow[dataColumn] = this.getParamValue(doc, parameter);
					}
				}
				dataTable.Rows.Add(dataRow);
			}
			dbFamily.AddType(dataTable);
		}

		private void 导入族文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.cmdImportFolder();
				return;
			}
			if (this.CurrentUser == null)
			{
				DlgLogin dlgLogin = new DlgLogin();
				if (dlgLogin.ShowDialog(this) == DialogResult.OK && dlgLogin.User != null)
				{
					if (dlgLogin.User.Status == UserStatus.Unregistered)
					{
						MessageBox.Show("您的账号未通过验证，请联系系统管理员。");
						return;
					}
					dlgLogin.User.IncreaseCount();
					this.CurrentUser = dlgLogin.User;
					this.cmdImportFolder();
					return;
				}
			}
			else
			{
				this.cmdImportFolder();
			}
		}

		private void cmdImportFolder()
		{
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
			folderBrowserDialog.Description = "提示：请选择要导入的\"分类文件夹\"，\"分类文件夹\"中包含族文件。";
			if (this.defaultfilePath != "")
			{
				folderBrowserDialog.SelectedPath = this.defaultfilePath;
			}
			if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
			{
				this.defaultfilePath = folderBrowserDialog.SelectedPath;
				DirectoryInfo rootDir = new DirectoryInfo(folderBrowserDialog.SelectedPath);
				int num = 0;
				this.FindCategoryByFolder(rootDir, ref num);
				List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();
				KeyValuePair<int, string> item = new KeyValuePair<int, string>(num, "族文件");
				list.Add(item);
				ProgressBarForm progressBarForm = new ProgressBarForm(list, "导入族文件夹", true);
				progressBarForm.Show();
				int num2 = 0;
				ExceptionInfo exceptionInfo = new ExceptionInfo();
				try
				{
					this.CreateCategoryByFolder(this.CurrentCategory, rootDir, progressBarForm, ref num2, exceptionInfo);
					progressBarForm.Dispose();
				}
				catch (Exception)
				{
					progressBarForm.Dispose();
				}
				if (exceptionInfo.IsException())
				{
					DlgExceptionInfo dlgExceptionInfo = new DlgExceptionInfo(exceptionInfo, num, num2);
					dlgExceptionInfo.ShowDialog();
				}
				else
				{
					MessageBox.Show("导入完成" + num2 + "个文件。", "族库管理");
				}
				FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, CheckType.All);
			}
		}

		private void cmdImportFolderToSubject()
		{
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
			folderBrowserDialog.Description = "提示：请选择要导入的\"专业文件夹\",专业文件夹中包含\"分类文件夹\"，\"分类文件夹\"中包含族文件。";
			if (this.defaultfilePath != "")
			{
				folderBrowserDialog.SelectedPath = this.defaultfilePath;
			}
			if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
			{
				this.defaultfilePath = folderBrowserDialog.SelectedPath;
				DirectoryInfo rootDir = new DirectoryInfo(folderBrowserDialog.SelectedPath);
				int num = 0;
				this.FindCategoryBySubjectFolder(rootDir, ref num);
				List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();
				KeyValuePair<int, string> item = new KeyValuePair<int, string>(num, "族文件");
				list.Add(item);
				ProgressBarForm progressBarForm = new ProgressBarForm(list, "导入族文件夹", true);
				progressBarForm.Show();
				int num2 = 0;
				ExceptionInfo exceptionInfo = new ExceptionInfo();
				try
				{
					this.CreateCategoryByFolder(this.CurrentSubject, rootDir, progressBarForm, ref num2, exceptionInfo);
					progressBarForm.Dispose();
				}
				catch (Exception)
				{
					progressBarForm.Dispose();
				}
				if (exceptionInfo.IsException())
				{
					DlgExceptionInfo dlgExceptionInfo = new DlgExceptionInfo(exceptionInfo, num, num2);
					dlgExceptionInfo.ShowDialog();
				}
				else
				{
					MessageBox.Show("导入完成" + num2 + "个文件。", "族库管理");
				}
				FamilyLibDatabase.FillTree(this.trCategory, this.mFamilyDatabases, CheckType.All);
			}
		}

		private void toolStripDropDownButton1_Click(object sender, EventArgs e)
		{
		}

		private void tsmiLogin_Click(object sender, EventArgs e)
		{
		}

		private void cmdLogout(bool showMessage = true)
		{
			this.CurrentUser = null;
			this.toolStripStatusLabel2.Text = "服务器管理账户当前未登录";
			this.tsddbCommunication.Enabled = false;
			this.tsmChangePass.Visible = false;
			this.tsLogout.Enabled = false;
			this.CurrentUser = null;
			if (showMessage)
			{
				MessageBox.Show("成功注销。");
			}
		}

		private void tsmiLogout_Click(object sender, EventArgs e)
		{
		}

		private void tsmiRegiste_Click(object sender, EventArgs e)
		{
		}

		private void tsmiChangePW_Click(object sender, EventArgs e)
		{
		}

		private void 加载ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			try
			{
				foreach (DbFamily dbFamily in this.CurrentCategory.GetAllFamilies(false, this.checkType))
				{
					dbFamily.Load(this.m_uiApp.ActiveUIDocument.Document);
				}
				MessageBox.Show("加载完成。");
			}
			catch
			{
				MessageBox.Show("加载异常。");
			}
		}

		private void 登陆ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.CurrentUser != null)
			{
				if (MessageBox.Show("当前已登录的账户：" + this.CurrentUser.Name + "，是否注销并更改用户登录？", "注销", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					this.cmdLogout(true);
					this.cmdLogin();
					return;
				}
			}
			else
			{
				this.cmdLogin();
			}
		}

		private void 注册ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgRegistrate dlgRegistrate = new DlgRegistrate(this.mGroup);
			dlgRegistrate.ShowDialog(this);
		}

		private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdLogout(true);
		}

		private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgChangePassword dlgChangePassword = new DlgChangePassword(this.CurrentUser.Name);
			dlgChangePassword.ShowDialog(this);
		}

		private void tsddbLogin_Click(object sender, EventArgs e)
		{
		}

		private void btnDownload_Click(object sender, EventArgs e)
		{
			this.cmdDownload();
		}

		private void cmdDownload()
		{
			if (!this.IsServer)
			{
				this.doDownload();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanExport())
				{
					this.doDownload();
					return;
				}
				MessageBox.Show("您的账号没有下载族的权限。");
			}
		}

		private void doDownload()
		{
			try
			{
				SqliteDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(this.CurrentFamily.Database.SubjectTable.SubjectType, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase.DownloadFamily(this.CurrentFamily.Database, sqliteDB, this.CurrentFamily);
				MessageBox.Show("下载成功。");
			}
			catch
			{
				MessageBox.Show("下载失败，请检查是否本地族库中已经包含此族。");
			}
		}

		private void 升级ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				if (MessageBox.Show("升级族库将要花费将近1-2个小时的时间，是否继续执行？", "族库升级", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
				{
					DlgProgress dlgProgress = new DlgProgress(new List<FamilyLibDatabase>
					{
						FamilyLibDatabase.GetSqliteDB(SubjectType.Architecture, (Convert.ToInt32(this.m_uiApp.Application.VersionNumber) - 1).ToString()),
						FamilyLibDatabase.GetSqliteDB(SubjectType.Electric, (Convert.ToInt32(this.m_uiApp.Application.VersionNumber) - 1).ToString()),
						FamilyLibDatabase.GetSqliteDB(SubjectType.HVAC, (Convert.ToInt32(this.m_uiApp.Application.VersionNumber) - 1).ToString()),
						FamilyLibDatabase.GetSqliteDB(SubjectType.Plumbing, (Convert.ToInt32(this.m_uiApp.Application.VersionNumber) - 1).ToString()),
						FamilyLibDatabase.GetSqliteDB(SubjectType.System, (Convert.ToInt32(this.m_uiApp.Application.VersionNumber) - 1).ToString()),
						FamilyLibDatabase.GetSqliteDB(SubjectType.MyCollect, (Convert.ToInt32(this.m_uiApp.Application.VersionNumber) - 1).ToString())
					}, this.m_uiApp);
					dlgProgress.ShowDialog(this);
				}
			}
			catch
			{
				MessageBox.Show("没有检测到上一版本族库。");
			}
		}

		private void toolStripDropDownButton2_Click(object sender, EventArgs e)
		{
		}

		public DbFamilySymbol DbFamilySymbo { get; set; }

		private void btnPlace_Click(object sender, EventArgs e)
		{
			if (this.dgvType.SelectedRows.Count > 0)
			{
				DataGridViewRow dataGridViewRow = this.dgvType.SelectedRows[0];
				this.DbFamilySymbo = this.currentFamily.Database.TypeTable[this.currentFamily, dataGridViewRow.Cells[1].Value.ToString()];
			}
		}

		private void 利用系数表ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.currentFamily == null || this.currentFamily.GetSubjectType() != SubjectType.Electric)
			{
				MessageBox.Show("请选择灯具。");
				return;
			}
			DbCategory dbCategory = this.currentFamily.Database.CategoryTable[this.currentFamily.ParentId];
			if (dbCategory.MainCategory().Name != "灯具")
			{
				MessageBox.Show("请选择灯具。");
				return;
			}
			DbData dbData = ConfigUtils.ReadFamilyLibXmlFile("族库类型", this.m_uiApp.Application.VersionNumber);
			DatabaseType databaseType = dbData.DatabaseType;
			Guid guid = this.currentFamily.Guid;
			string connStr = this.currentFamily.Database.ConnStr;
			int eid = this.currentFamily.ExData.Eid1;
			string utilizationFactor = UtilizationFactor.GetUtilizationFactor(databaseType, connStr, guid, ref eid);
			this.currentFamily.ExData.Eid1 = eid;
			this.currentFamily.Database.FamilyTable.Update(this.currentFamily);
			DataTable dataTable = this.currentFamily.Database.TypeTable.DataTable(this.currentFamily);
			if (dataTable == null)
			{
				return;
			}
			foreach (object obj in dataTable.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				try
				{
					dataRow["利用系数表"] = utilizationFactor;
				}
				catch
				{
				}
			}
			this.currentFamily.Database.TypeTable.Update(dataTable, this.currentFamily);
			this.dgvType.DataSource = dataTable;
		}

		private void 按日期查询ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgSearchByTime instance = DlgSearchByTime.GetInstance(this, this.mFamilyDatabases);
			if (instance.ShowDialog(this) == DialogResult.OK)
			{
				List<DbFamily> list = instance.Database.FamilyTable.SearchFamily(instance.StartTime, instance.EndTime);
				if (list.Count == 0)
				{
					MessageBox.Show("没有找到符合搜索条件的族。");
					return;
				}
				this.btnTop.Enabled = false;
				this.btnBottom.Enabled = false;
				this.btnNext.Enabled = false;
				this.btnPrevious.Enabled = false;
				this.cbxPageCount.Items.Clear();
				this.dgvType.DataSource = "";
				this.mListFamilys.Clear();
				this.mListFamilys.AddRange(list);
				this.pageCount = this.ComputePageCount();
				this.label2.Text = "/" + this.pageCount.ToString();
				this.cbxPageCount.Items.Clear();
				for (int i = 1; i <= this.pageCount; i++)
				{
					this.cbxPageCount.Items.Add(i);
				}
				if (this.cbxPageCount.Items.Count > 0)
				{
					this.cbxPageCount.SelectedIndex = 0;
				}
			}
		}

		private void 按族名查询ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgSearchByName instance = DlgSearchByName.GetInstance(this, this.mFamilyDatabases);
			if (instance.ShowDialog(this) == DialogResult.OK)
			{
				List<DbFamily> list = instance.Database.FamilyTable.SearchFamily(instance.FamilyName);
				if (list.Count == 0)
				{
					MessageBox.Show("没有找到符合搜索条件的族。");
					return;
				}
				this.btnTop.Enabled = false;
				this.btnBottom.Enabled = false;
				this.btnNext.Enabled = false;
				this.btnPrevious.Enabled = false;
				this.cbxPageCount.Items.Clear();
				this.dgvType.DataSource = "";
				this.mListFamilys.Clear();
				this.mListFamilys.AddRange(list);
				this.pageCount = this.ComputePageCount();
				this.label2.Text = "/" + this.pageCount.ToString();
				this.cbxPageCount.Items.Clear();
				for (int i = 1; i <= this.pageCount; i++)
				{
					this.cbxPageCount.Items.Add(i);
				}
				if (this.cbxPageCount.Items.Count > 0)
				{
					this.cbxPageCount.SelectedIndex = 0;
					this.currentFamily = (this.cbxPageCount.SelectedItem as DbFamily);
				}
			}
		}

		private void 最近使用ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			string sqlStr = "select * from FamilyTable where UseDate > 0";
			List<DbFamily> list = new List<DbFamily>();
			foreach (FamilyLibDatabase familyLibDatabase in this.mFamilyDatabases)
			{
				ConnectionState state = familyLibDatabase.Connection.State;
				if (state == ConnectionState.Closed)
				{
					familyLibDatabase.Connection.Open();
				}
				DataTable dataTable = familyLibDatabase.ExecQuery(sqlStr);
				if (state == ConnectionState.Closed)
				{
					familyLibDatabase.Connection.Close();
				}
				if (dataTable != null && dataTable.Rows.Count > 0)
				{
					for (int i = 0; i < dataTable.Rows.Count; i++)
					{
						byte[] buffer = (byte[])dataTable.Rows[i]["FamilyImg"];
						Image img = new Bitmap(new MemoryStream(buffer));
						DbFamily dbFamily = new DbFamily(dataTable.Rows[i]["FamilyName"].ToString().Trim(), img, new Guid(dataTable.Rows[i]["GUID"].ToString()));
						dbFamily.Limit = Convert.ToBoolean(dataTable.Rows[i]["Limit"].ToString());
						dbFamily.Version = dataTable.Rows[i]["Version"].ToString().Trim();
						dbFamily.SetDate(Convert.ToDateTime(dataTable.Rows[i]["Date"].ToString()));
						dbFamily.Description = dataTable.Rows[i]["Description"].ToString().Trim();
						dbFamily.SetParentId(new Guid(dataTable.Rows[i]["ParentId"].ToString()));
						dbFamily.SetDatabase(familyLibDatabase);
						dbFamily.KeyName = dataTable.Rows[i]["KeyName"].ToString();
						if (dataTable.Rows[i]["eID1"].ToString() != "")
						{
							dbFamily.ExData.Eid1 = Convert.ToInt32(dataTable.Rows[i]["eID1"].ToString());
						}
						if (dataTable.Rows[i]["eID2"].ToString() != "")
						{
							dbFamily.ExData.Eid2 = Convert.ToInt32(dataTable.Rows[i]["eID2"].ToString());
						}
						dbFamily.ExData.Tag1 = dataTable.Rows[i]["tag1"].ToString();
						dbFamily.ExData.Tag2 = dataTable.Rows[i]["tag2"].ToString();
						dbFamily.Check = (bool)dataTable.Rows[i]["Check"];
						dbFamily.Count = Convert.ToInt32(dataTable.Rows[i]["Count"].ToString());
						if (dataTable.Rows[i]["UseDate"].ToString() != "")
						{
							dbFamily.SetUseDate(Convert.ToDateTime(dataTable.Rows[i]["UseDate"].ToString()));
						}
						list.Add(dbFamily);
					}
				}
			}
			if (list.Count == 0)
			{
				MessageBox.Show("没有找到符合搜索条件的族。");
				return;
			}
			this.btnTop.Enabled = false;
			this.btnBottom.Enabled = false;
			this.btnNext.Enabled = false;
			this.btnPrevious.Enabled = false;
			this.cbxPageCount.Items.Clear();
			this.dgvType.DataSource = "";
			this.mListFamilys.Clear();
			this.mListFamilys.AddRange(list);
			this.sorter.SortColumn = 5;
			this.sorter.SortOrder = SortOrder.Descending;
			for (int j = 0; j < this.mListFamilys.Count - 1; j++)
			{
				for (int k = j + 1; k < this.mListFamilys.Count; k++)
				{
					if (this.mListFamilys[j].UseDate < this.mListFamilys[k].UseDate)
					{
						DbFamily value = this.mListFamilys[j];
						this.mListFamilys[j] = this.mListFamilys[k];
						this.mListFamilys[k] = value;
					}
				}
			}
			this.pageCount = this.ComputePageCount();
			this.label2.Text = "/" + this.pageCount.ToString();
			this.cbxPageCount.Items.Clear();
			for (int l = 1; l <= this.pageCount; l++)
			{
				this.cbxPageCount.Items.Add(l);
			}
			if (this.cbxPageCount.Items.Count > 0)
			{
				this.cbxPageCount.SelectedIndex = 0;
				this.currentFamily = (this.cbxPageCount.SelectedItem as DbFamily);
			}
		}

		private void 上传利用系数表ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.doUploadLYXS();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanImport())
				{
					this.doUploadLYXS();
					return;
				}
				MessageBox.Show("您的账号没有上传利用系数表的权限。");
			}
		}

		private void doUploadLYXS()
		{
			try
			{
				string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
				string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "Server", "value");
				string dataFromConfigFile2 = XmlUtils.GetDataFromConfigFile(fileName, "Uid", "value");
				string dataFromConfigFile3 = XmlUtils.GetDataFromConfigFile(fileName, "Pwd", "value");
				ConnectData cd = new ConnectData(dataFromConfigFile, dataFromConfigFile2, dataFromConfigFile3);
				FamilyLibDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase sqlServerDB = FamilyLibDatabase.GetSqlServerDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber, cd);
				if (UtilizationFactor.DataDownloadServer(DatabaseType.Local, sqliteDB.ConnStr, DatabaseType.Server, sqlServerDB.ConnStr))
				{
					MessageBox.Show("同步成功。");
				}
				else
				{
					MessageBox.Show("同步失败。");
				}
			}
			catch
			{
				MessageBox.Show("数据库链接失败，请先配置服务器连接。");
			}
		}

		private void 下载利用系数表ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.doDownloadLYXS();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanExport())
				{
					this.doDownloadLYXS();
					return;
				}
				MessageBox.Show("您的账号没有下载利用系数表的权限。");
			}
		}

		private void doDownloadLYXS()
		{
			try
			{
				string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
				string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "Server", "value");
				string dataFromConfigFile2 = XmlUtils.GetDataFromConfigFile(fileName, "Uid", "value");
				string dataFromConfigFile3 = XmlUtils.GetDataFromConfigFile(fileName, "Pwd", "value");
				ConnectData cd = new ConnectData(dataFromConfigFile, dataFromConfigFile2, dataFromConfigFile3);
				FamilyLibDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase sqlServerDB = FamilyLibDatabase.GetSqlServerDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber, cd);
				if (UtilizationFactor.DataDownloadServer(DatabaseType.Server, sqlServerDB.ConnStr, DatabaseType.Local, sqliteDB.ConnStr))
				{
					MessageBox.Show("同步成功。");
				}
				else
				{
					MessageBox.Show("同步失败。");
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void timer1_Tick(object sender, EventArgs e)
		{
			try
			{
				if (this.CurrentUser != null)
				{
					if (this.CurrentUser.NewMessageCount > 0)
					{
						this.tsddbCommunication.Text = "通讯(" + this.CurrentUser.NewMessageCount + ")";
						this.tsmiInbox.Text = "收件箱(" + this.CurrentUser.NewMessageCount + ")";
					}
					else
					{
						this.tsddbCommunication.Text = "通讯";
						this.tsmiInbox.Text = "收件箱";
					}
					this.initPermission();
				}
			}
			catch
			{
				this.timer1.Stop();
				this.timer1.Enabled = false;
				MessageBox.Show("无法连接到服务器，请检查网络是否畅通。");
			}
		}

		private void tsmiAddRole_Click(object sender, EventArgs e)
		{
		}

		private void tsmiRemove_Click(object sender, EventArgs e)
		{
			DlgRemoveRole dlgRemoveRole = new DlgRemoveRole(this.mGroup);
			dlgRemoveRole.ShowDialog(this);
		}

		private void tsmiSetRight_Click(object sender, EventArgs e)
		{
			DlgSetRight dlgSetRight = new DlgSetRight(this.mGroup);
			dlgSetRight.ShowDialog(this);
		}

		private void tsmiSetRole_Click(object sender, EventArgs e)
		{
			DlgSetRole dlgSetRole = new DlgSetRole(this.mGroup);
			dlgSetRole.ShowDialog(this);
		}

		private void initPermission()
		{
			this.tsddbCommunication.Visible = false;
			this.tsmChangePass.Visible = true;
			this.tsddbCommunication.Visible = true;
			this.tsddbCommunication.Enabled = true;
		}

		private void tsmiSent_Click(object sender, EventArgs e)
		{
			DlgSendMessage dlgSendMessage = new DlgSendMessage(this.CurrentUser);
			dlgSendMessage.ShowDialog(this);
		}

		private void tsmiInbox_Click(object sender, EventArgs e)
		{
			DlgMessageBox dlgMessageBox = new DlgMessageBox(this.CurrentUser);
			dlgMessageBox.ShowDialog(this);
		}

		private void tsmiDelUser_Click(object sender, EventArgs e)
		{
			DlgRemoveUser dlgRemoveUser = new DlgRemoveUser();
			dlgRemoveUser.ShowDialog(this);
		}

		private void 添加职位ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			DlgAddRole dlgAddRole = new DlgAddRole(this.mGroup);
			dlgAddRole.ShowDialog(this);
		}

		private void 删除职位ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			DlgRemoveRole dlgRemoveRole = new DlgRemoveRole(this.mGroup);
			dlgRemoveRole.ShowDialog(this);
		}

		private void 权限设置ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgSetRight dlgSetRight = new DlgSetRight(this.mGroup);
			dlgSetRight.ShowDialog(this);
		}

		private void tsmiVerifyUser_Click(object sender, EventArgs e)
		{
		}

		private void 删除用户ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgRemoveUser dlgRemoveUser = new DlgRemoveUser();
			dlgRemoveUser.ShowDialog(this);
		}

		private void 职位设置ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgSetRole dlgSetRole = new DlgSetRole(this.mGroup);
			dlgSetRole.ShowDialog(this);
		}

		private void toolStripMenuItem4_Click(object sender, EventArgs e)
		{
			DlgSendMessage dlgSendMessage = new DlgSendMessage(this.CurrentUser);
			dlgSendMessage.ShowDialog(this);
		}

		private void 收件箱ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgMessageBox dlgMessageBox = new DlgMessageBox(this.CurrentUser);
			dlgMessageBox.ShowDialog(this);
		}

		private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
		{
		}

		private void 添加参数ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgAddParam dlgAddParam = new DlgAddParam(this.m_uiApp.ActiveUIDocument.Document, this.currentFamily);
			dlgAddParam.ShowDialog(this);
			this.ShowType();
		}

		private void gUID查看ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			FamilyUtil.TestGUID(this.m_uiApp);
		}

		private void gUID更新ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			FamilyUtil.UpdateGUIDTool(this.m_uiApp);
		}

		private void 图片更新ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			FamilyUtil.UpdateImgTool(this.m_uiApp);
		}

		private void clearToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.m_uiApp.ActiveUIDocument.Document.PathName == "")
			{
				MessageBox.Show("请先保存新建项目后再运行清理扩展数据功能", "盈建科提示");
				return;
			}
			FamilyUtil.ClearFamilyData(this.m_uiApp);
		}

		private void removeEntToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void qToolStripMenuItem_Click(object sender, EventArgs e)
		{
			FamilyLibDatabase database = this.currentSubject.Database;
			foreach (DbCategory dbCategory in database.CategoryTable.GetAll())
			{
				dbCategory.Remove(true);
			}
		}

		private void btnExpExcel_Click(object sender, EventArgs e)
		{
			this.dgvType.ExportExcel();
		}

		private void dgvType_ColumnHeaderMouseClick_1(object sender, DataGridViewCellMouseEventArgs e)
		{
		}

		private void 评论ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.CurrentUser != null)
			{
				DlgCommentary dlgCommentary = new DlgCommentary(this.CurrentUser, this.currentFamily);
				dlgCommentary.ShowDialog(this);
				return;
			}
			MessageBox.Show("请先登录再评论。");
		}

		private void rbCheck_CheckedChanged(object sender, EventArgs e)
		{
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (this.checkBox1.Checked)
			{
				this.checkType = CheckType.Checked;
			}
			else
			{
				this.checkType = CheckType.All;
			}
			if (((CheckBox)sender).Checked)
			{
				this.SelectDb();
			}
		}

		private void 审核ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.doCheck();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanCheckFamily())
				{
					this.doCheck();
					return;
				}
				MessageBox.Show("您的账号没有审核族的权限。");
			}
		}

		private void doCheck()
		{
			DlgCheck dlgCheck = new DlgCheck(this.mFamilyDatabases);
			dlgCheck.ShowDialog();
		}

		private void lvFamily_ColumnClick(object sender, ColumnClickEventArgs e)
		{
			if (e.Column == this.sorter.SortColumn)
			{
				if (this.sorter.SortOrder == SortOrder.Ascending)
				{
					this.sorter.SortOrder = SortOrder.Descending;
				}
				else
				{
					if (this.sorter.SortOrder != SortOrder.Descending)
					{
						return;
					}
					this.sorter.SortOrder = SortOrder.Ascending;
				}
			}
			else
			{
				this.sorter.SortColumn = e.Column;
			}
			this.lvFamily.Sort();
		}

		private void 导入族文件夹ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.cmdImportFolderToSubject();
				return;
			}
			if (this.CurrentUser == null)
			{
				DlgLogin dlgLogin = new DlgLogin();
				if (dlgLogin.ShowDialog(this) == DialogResult.OK && dlgLogin.User != null)
				{
					if (dlgLogin.User.Status == UserStatus.Unregistered)
					{
						MessageBox.Show("您的账号未通过验证，请联系系统管理员。");
						return;
					}
					dlgLogin.User.IncreaseCount();
					this.CurrentUser = dlgLogin.User;
					this.cmdImportFolderToSubject();
					return;
				}
			}
			else
			{
				this.cmdImportFolderToSubject();
			}
		}

		private void DlgMain_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.cmdLogout(false);
		}

		private void btnClearSubject_Click(object sender, EventArgs e)
		{
			if (this.m_uiApp.ActiveUIDocument.Document.PathName == "")
			{
				MessageBox.Show("请先保存新建项目后再运行此功能", "盈建科提示");
				return;
			}
			string str;
			if (this.rbLocal.Checked)
			{
				str = "盈建科库";
			}
			else
			{
				if (!this.rbServer.Checked)
				{
					MessageBox.Show("请选择盈建科库或者服务器库。");
					return;
				}
				str = "服务器库";
			}
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
			folderBrowserDialog.Description = "请选择空文件夹:";
			if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
			{
				string str2 = folderBrowserDialog.SelectedPath + "\\" + str;
				foreach (FamilyLibDatabase familyLibDatabase in this.mFamilyDatabases)
				{
					string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(familyLibDatabase.Name);
					string text = str2 + "\\" + fileNameWithoutExtension;
					Dictionary<string, Dictionary<string, byte[]>> allFileInfos = familyLibDatabase.FamilyFileTable.GetAllFileInfos();
					Dictionary<string, string> dictionary = new Dictionary<string, string>();
					string text2 = "";
					foreach (KeyValuePair<string, Dictionary<string, byte[]>> keyValuePair in allFileInfos)
					{
						if (!Directory.Exists(text))
						{
							Directory.CreateDirectory(text);
						}
						text2 = text + "\\" + keyValuePair.Value.Keys.First<string>() + ".rfa";
						Assist.FileUtil.WriteFile(keyValuePair.Value.Values.First<byte[]>(), text2);
						dictionary.Add(keyValuePair.Key, keyValuePair.Value.Keys.First<string>());
					}
					string[] paths = new string[]
					{
						text2
					};
					FamilyUtil.ClearFamilyData(this.m_uiApp, paths);
					DirectoryInfo directoryInfo = new DirectoryInfo(text);
					foreach (FileInfo fileInfo in directoryInfo.GetFiles())
					{
						if (fileInfo.Extension == ".rfa")
						{
							foreach (KeyValuePair<string, string> keyValuePair2 in dictionary)
							{
								if (keyValuePair2.Value == Path.GetFileNameWithoutExtension(fileInfo.FullName))
								{
									byte[] fileBytes = Assist.FileUtil.ReadFile(fileInfo.FullName);
									familyLibDatabase.FamilyFileTable.Replace(keyValuePair2.Key, fileBytes);
								}
							}
						}
					}
					MessageBox.Show("专业：" + fileNameWithoutExtension + "清理完成。");
				}
			}
		}

		private void MyCollectFamilyAddMenuItem_Click(object sender, EventArgs e)
		{
			if (this.m_uiApp.ActiveUIDocument.Document.PathName == "")
			{
				MessageBox.Show("请先保存新建项目后再运行添加族功能", "盈建科提示");
				return;
			}
			this.doAddFamily();
		}

		private void MyCollectFamilyDeleteMenuItem_Click(object sender, EventArgs e)
		{
			this.doRemoveFamily();
			this.Recount();
			this.CurrentFamily = null;
		}

		private void MyCollectFamilyReNameMenuItem_Click(object sender, EventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count > 0)
			{
				this.lvFamily.LabelEdit = true;
				this.lvFamily.SelectedItems[0].BeginEdit();
			}
		}

		private void MyCollectFamilyEditMenuItem_Click(object sender, EventArgs e)
		{
			this.doEditFamily();
		}

		private void MyCollectFamilyLoadMenuItem_Click(object sender, EventArgs e)
		{
			UIDocument activeUIDocument = this.m_uiApp.ActiveUIDocument;
			Document document = activeUIDocument.Document;
			Family family = this.CurrentFamily.Load(document);
			try
			{
				if (family.Document.PathName == document.PathName)
				{
					MessageBox.Show("加载完成。");
				}
				else
				{
					MessageBox.Show("加载失败。");
				}
			}
			catch
			{
				MessageBox.Show("加载失败。");
			}
		}

		private void MyCollectFamilyAddParamMenuItem_Click(object sender, EventArgs e)
		{
			DlgAddParam dlgAddParam = new DlgAddParam(this.m_uiApp.ActiveUIDocument.Document, this.currentFamily);
			dlgAddParam.ShowDialog(this);
			this.ShowType();
		}

		private void 加入我的收藏ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count > 0)
			{
				TreeNode[] array = this.trCategory.Nodes.Find("我的收藏", false);
				TreeNode treeNode = array[0];
				if (treeNode.Nodes.Count < 1)
				{
					MessageBox.Show("只能在分类下添加，请先在 我的收藏 下建立分类。");
					return;
				}
				TreeNode nodeMyCollect = null;
				if (treeNode.GetNodeCount(true) == 1)
				{
					nodeMyCollect = treeNode.FirstNode;
				}
				else
				{
					DlgSelectCategory dlgSelectCategory = new DlgSelectCategory(treeNode);
					if (dlgSelectCategory.ShowDialog() != DialogResult.OK || dlgSelectCategory.CurTreeNode == null)
					{
						return;
					}
					nodeMyCollect = dlgSelectCategory.CurTreeNode;
				}
				List<DbFamily> list = new List<DbFamily>();
				foreach (object obj in this.lvFamily.SelectedItems)
				{
					ListViewItem listViewItem = (ListViewItem)obj;
					DbFamily item = (DbFamily)listViewItem.Tag;
					list.Add(item);
				}
				this.doAddFamilyToMyCollect(list, nodeMyCollect);
			}
		}

		private void doAddFamilyToMyCollect(List<DbFamily> lstFamily, TreeNode nodeMyCollect)
		{
			List<DbFamily> list = new List<DbFamily>();
			foreach (DbFamily dbFamily in lstFamily)
			{
				if (this.AddFamilyToMyCollect(dbFamily, nodeMyCollect, false) != "OK")
				{
					list.Add(dbFamily);
				}
			}
			if (list.Count < 1)
			{
				MessageBox.Show("成功加入我的收藏！");
			}
			else if (list.Count == 1)
			{
				DbFamily dbFamily2 = list[0];
				string text = "我的收藏中已有同名族\"" + dbFamily2.Name + "\"，是否覆盖已有同名族？";
				if (MessageBox.Show(text, "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
				{
					Parent parent = (Parent)nodeMyCollect.Tag;
					DbFamily dbFamily3 = parent.Database.FamilyTable[dbFamily2.Name];
					dbFamily3.Remove(false);
					this.AddFamilyToMyCollect(dbFamily2, nodeMyCollect, true);
					MessageBox.Show("成功加入我的收藏！");
				}
			}
			else
			{
				ExceptionInfo exceptionInfo = new ExceptionInfo();
				foreach (DbFamily dbFamily4 in list)
				{
					exceptionInfo.AddNameException(dbFamily4.Name, dbFamily4.Database.Name);
				}
				if (exceptionInfo.IsException())
				{
					DlgExceptionInfo dlgExceptionInfo = new DlgExceptionInfo(exceptionInfo, lstFamily.Count, lstFamily.Count - list.Count);
					dlgExceptionInfo.ShowDialog();
				}
			}
			TreeNode count = this.FindRoot(nodeMyCollect);
			this.setCount(count);
		}

		private string AddFamilyToMyCollect(DbFamily family, TreeNode nodeMyCollect, bool bOverWrite)
		{
			DbCategory dbCategory = (DbCategory)nodeMyCollect.Tag;
			if (dbCategory.Database.FamilyTable[family.Name] != null && !bOverWrite)
			{
				return "已有同名族。";
			}
			DbFamily dbFamily = new DbFamily(family.Name, family.Image);
			dbFamily.Name = family.Name;
			dbFamily.Version = family.Version;
			dbFamily.SetDate(DateTime.Now);
			dbFamily.Description = family.Description;
			dbFamily.LargeImage = family.LargeImage;
			dbFamily.TwoDImage = family.TwoDImage;
			dbFamily.Count = 0;
			dbFamily.ParamDefinitionList.AddRange(family.Database.FamilyParamTable[family]);
			dbCategory.AddFamily(dbFamily, family.Database.FamilyFileTable[family]);
			dbFamily.AddType(family.Database.TypeTable.DataTable(family));
			return "OK";
		}

		private void DlgMain_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private static DlgMain main;

		private string mGroup = "FM";

		private UIApplication m_uiApp;

		public List<FamilyLibDatabase> mFamilyDatabases = new List<FamilyLibDatabase>();

		public List<DbFamily> mListFamilys = new List<DbFamily>();

		public DbSubject currentSubject;

		public DbCategory currentCategory;

		public DbFamily currentFamily;

		private bool boEdit;

		private bool boAdd;

		public string initialDirectory = "C:\\";

		public static int pageContainment = 24;

		private int pageCount;

		private int addRowsNo;

		private string userPath = "";

		private RadioButton rbTemp;

		private bool IsServer;

		private DbUser CurrentUser;

		private string defaultfilePath = "";

		private CheckType checkType = CheckType.All;

		private ListViewSorter sorter;

		public class ListViewColumnSorter : IComparer
		{
			public ListViewColumnSorter()
			{
				this.ColumnToSort = 0;
				this.OrderOfSort = SortOrder.None;
				this.ObjectCompare = new CaseInsensitiveComparer();
			}

			public int Compare(object x, object y)
			{
				return 0;
			}

			public int ColumnToSort;

			public SortOrder OrderOfSort;

			private CaseInsensitiveComparer ObjectCompare;
		}
	}
}
